随笔分类 - linux shell
摘要:001、let [root@pc1 test1]# a=1 [root@pc1 test1]# echo $a 1 [root@pc1 test1]# let a=$a+50 ## 数值变量递加 [root@pc1 test1]# echo $a 51 002、使用括号(()) [root@pc1
阅读全文
摘要:通常更推荐使用双方引号。 001、双方引号可以避免变量的单词分割 [root@pc1 test1]# str1="aa bb" ## 测试字符串 [root@pc1 test1]# if [[ $str1 == "aa bb" ]]; then echo "yes"; fi ## 双边引号不用担心变
阅读全文
摘要:内部字符单分隔符(Internal Field Separator,IFS) 是一个系统环境变量; 无法使用echo $IFS进行查看 001、查看IFS [root@pc1 test1]# set | grep "^IFS" ## 系统默认的IFS IFS=$' \t\n' [root@pc1 t
阅读全文
摘要:001、 (base) [b20223040323@admin1 test2]$ ls test.txt (base) [b20223040323@admin1 test2]$ cat test.txt ## 测试数据如下;根据第一列和第三列对数据进行去重复 ID=gene-RIN1 rna-XM_
阅读全文
摘要:next 是跳过当前行(awk自身是列循环和行循环的结合); continue是跳过当前循环(跳过列循环); 001、next;跳过当前行 (base) [b20223040323@admin1 test2]$ ls a.txt (base) [b20223040323@admin1 test2]$
阅读全文
摘要:001、 (base) [b20223040323@admin1 test2]$ cat 003.txt ## 测试数据如下,第一列有多个项,且部分项有重复,实现根据第三列筛选出最大的项 ID=gene-TRNAC-GCA rna-TRNAC-GCA 72 ID=gene-ATP5O rna-XM_
阅读全文
摘要:\b表示限位符,\B表示与\b相反的匹配 01、\b [root@PC1 test2]# ls a.txt [root@PC1 test2]# cat a.txt ## 测试数据 ab xyky 3d ma abki ff ec dfab ff fg ab kk ad ff ab ad fabe j
阅读全文
摘要:01、先排序,然后取首尾(数据大时不适用) [root@pc1 test1]# ls a.txt [root@pc1 test1]# cat a.txt ## 测试文件 8 3 39 28 2 4 6 [root@pc1 test1]# sort -n a.txt | head -n 1 ## 最小
阅读全文
摘要:001、将每行的首字母大写 a、 [root@PC1 test1]# ls a.txt [root@PC1 test1]# cat a.txt ## 测试文件 aa bb cc dd ee ff gg hh qq [root@PC1 test1]# sed 's/^[a-z]/\U&/' a.txt
阅读全文
摘要:001、 [root@PC1 test1]# ls a.txt [root@PC1 test1]# cat a.txt ## 测试文本 aa bb ee 33 ff rr aa ff yy [root@PC1 test1]# awk 'NR == 2 {printf("%s\t%d\n", $2,
阅读全文
摘要:001、方法1 双文件 [root@PC1 test1]# ls a.txt cols.list [root@PC1 test1]# cat cols.list ## 列 1 3 5 8 [root@PC1 test1]# cat a.txt ## 测试文件 001 002 003 004 005
阅读全文
摘要:001、直接合并 [root@PC1 test1]# str1=aa [root@PC1 test1]# str2=bb ## 测试字符串 [root@PC1 test1]# str3=$str1$str2 ## 直接合并 [root@PC1 test1]# echo $str3 ## 输出合并结果
阅读全文
摘要:001、字符串转换为shell数组 [root@PC1 test1]# str1="aa bb 100 200 500" ## 生成测试字符串 [root@PC1 test1]# echo $str1 aa bb 100 200 500 [root@PC1 test1]# ay1=($str1) #
阅读全文
摘要:001、字符串变量传入awk,然后转换为数组 [root@PC1 test1]# str1="1 3 7 8" ## 测试字符串 [root@PC1 test1]# awk -v a="$str1" 'BEGIN{split(a, ay1, " "); print length(ay1)}' ##
阅读全文
摘要:001、先看整体结构 [root@PC1 test1]# ls ## 测试文件及目录 a.txt test001 test002 test003 [root@PC1 test1]# tree -h ## 查看结构和各个文件的大小 . ├── [ 59] a.txt ├── [ 30] test001
阅读全文
摘要:001、 -w选项锁定 [root@PC1 test1]# ls a.txt [root@PC1 test1]# cat a.txt ## 测试文本 3432 dsab45cdf 887 abc 33333 77777 sdf fffabc 8888 ddd kk22,kk33k wwww sss
阅读全文
摘要:\w ## 匹配文字和数字字符,也就是[A-Za-z0-9], \W ## \w的反置形式,匹配一个或多个非单词字符,如点号句号等。 01、 [root@PC1 test1]# ls a.txt [root@PC1 test1]# cat a.txt ## 测试文本 3432 dsab45cdf 8
阅读全文
摘要:001、 -a: 显示所有目录及文件的大小 [root@PC1 test1]# ls ## 测试文件及目录 a.txt test001 test002 test003 [root@PC1 test1]# du -ah ## 输出所有文件及目录的大小 4.0K ./a.txt 1000M ./test
阅读全文
摘要:001、 [root@PC1 test]# ls a.txt [root@PC1 test]# cat a.txt ## 测试文件 yy 33 gg ss ff 11 zz mm dd 88 44 cc [root@PC1 test]# awk 'NF' a.txt ## 每行重复1次 yy 33
阅读全文
摘要:001、 [root@PC1 test]# ls a.txt [root@PC1 test]# cat a.txt ## 测试数据 444 777 222 999 eee 333 222 666 111 ggg sss fff zzz mmm nnn rrr ttt hhh [root@PC1 te
阅读全文

浙公网安备 33010602011771号