随笔分类 - linux shell
摘要:001、 [root@pc1 test]# ls a.txt [root@pc1 test]# sum=0 [root@pc1 test]# cat a.txt | while read i; do let sum+=$i; done ## 循环方式1 [root@pc1 test]# echo $
阅读全文
摘要:001、awk [root@pc1 test01]# ls a.txt [root@pc1 test01]# cat a.txt 8 3 2 5 [root@pc1 test01]# awk '{sum += $1} END {print sum}' a.txt ## awk计算第一列数据的和 18
阅读全文
摘要:001、 如下测试数据,想在每行最后的两个字符之前添加特定字符,比如QQ,如何实现 [root@pc1 test01]# ls a.txt [root@pc1 test01]# cat a.txt ## 测试数据 2+adey 2-ddfr 7_dgqd 002、可以借助&实现 [root@pc1
阅读全文
摘要:Linux中文件的隐藏权限通常有2个参数; i 和 a; 使用chattr 修改文件的隐藏权限; 使用lsattr 查看文件的隐藏权限; 001、-i参数; a、对文件:无法对文件进行修改; b、对目录:仅能修改目录中的子文件的内容而不能新建或者删除文件 01、增加、查看文件的-i隐藏属性 [roo
阅读全文
摘要:001、测试数据 [root@pc1 test01]# ls a.txt idx.txt [root@pc1 test01]# cat a.txt ## 测试数据 01 02 03 04 05 06 1 07 08 09 10 11 12 2 13 14 15 16 17 18 3 19 20 21
阅读全文
摘要:001、 [root@pc1 test]# ls a.txt [root@pc1 test]# cat a.txt ## 测试数据 aa bb cc aa jj kk aa mm uy aa mm ww [root@pc1 test]# grep "aa\t" a.txt ##\t在这里不能被识别,
阅读全文
摘要:001、R语言出现如下报错: 读取的项目数必需是列数的倍数 > egg <- read.table("XXX.emapper_reformat.annotations",sep="\t",header=T) Warning messages: 1: In scan(file = file, what
阅读全文
摘要:eggnog.db.gzeggnog_proteins.dmnd.gzeggnog.taxa.tar.gzmmseqs.tar.gzpfam.tar.gz
阅读全文
摘要:001、问题 locate定位文件的时候出现如下问题: locate: can not stat () `/var/lib/mlocate/mlocate.db': No such file or directory 002、原因分析; 安装locate命令后没有更新 解决方法:更新命令库,使用如下
阅读全文
摘要:001、 [root@pc1 test1]# ls a.txt [root@pc1 test1]# cat a.txt 5 8 2 7 3 [root@pc1 test1]# awk '{if(NR == 1) {idx = NR; value = $1}; if($1 > value) {idx
阅读全文
摘要:001、脚本解释器用于说明程序执行的方式。 [root@pc1 test1]# ls ## 两个测试脚本, test02.script 相比于test01.script多了指定python解释器的语句 #!/usr/bin/env python test01.script test02.script
阅读全文
摘要:001、为了避免脚本多次执行,生成结果多次追加,可以在追加语句的前面增加清空语句避免多次追加 [root@pc1 test1]# ls a.sh [root@pc1 test1]# cat a.sh ## 测试脚本 #!/bin/bash > result.txt ## 或者使用 rm -f res
阅读全文
摘要:001、在特定的情况下,为了防止脚本重复执行,造成混乱,可以在末尾追加如下语句避免脚本重复执行 [root@pc1 test1]# ls a.sh [root@pc1 test1]# cat a.sh ## 测试脚本 #!/bin/bash seq 2 seq 2 sed -i 's/^/#/' $
阅读全文
摘要:linux 中declare命令的用法 001、声明整数型变量 [root@pc1 test1]# declare -i var1 ## 声明变量为整数型变量 [root@pc1 test1]# var1=132 ## 赋值整数型变量 [root@pc1 test1]# echo $var1 ##
阅读全文
摘要:linux shell脚本中 =~ 的作用 =~ 表示正则表达式左侧是否匹配右侧。 001、举例如下: [root@pc1 test1]# str1=12343 ## 纯数字字符串 [root@pc1 test1]# str2=abdef ## 字母字符串 [root@pc1 test1]# str
阅读全文
摘要:linux 中如何判断变量是否为数值 001、 利用正则表达式判断 a、 [root@pc1 test1]# str1="abcd" ## 字母字符串 [root@pc1 test1]# str2="100" ## 数字字符串 [root@pc1 test1]# re="^[-+]?[0-9]+([
阅读全文
摘要:linux 中正则表达式中?号的作用是匹配前面的字母0次或者1次; 001、测试如下: [root@pc1 test1]# ls a.txt [root@pc1 test1]# cat a.txt ## 测试样本 abcd xyz 133 kkkk abde jjj dddu abbcde jjj
阅读全文
摘要:001、 [root@pc1 test2]# ls a.txt [root@pc1 test2]# cat a.txt ## 测试数据 xx yy$ kk ff ee 88 uu ee ww$ [root@pc1 test2]# grep "$" a.txt ## grep直接检测,检测不到 xx
阅读全文
摘要:linux 中条件测试 case 语句。 case语句用于多重判断匹配;若匹配成功,则执行相关的命令,并结束整个条件测试;若匹配不成功,则执行默认的命令; linux shell 中case 条件判断的首个单词是case, 第一句的结束是 in; 单项匹配判断的结尾是); 单项匹配的结束时两个分号;
阅读全文
摘要:linux shell 中实现进度条: #! /bin/bash total_steps=100 for ((step=1; step<=total_steps; step++)); do printf "\r[%-50s] %d%%" $(printf "#%.0s" $(seq 1 $((ste
阅读全文

浙公网安备 33010602011771号