随笔分类 -  linux shell

上一页 1 ··· 8 9 10 11 12 13 14 15 16 ··· 77 下一页
摘要:001、 -c: complement:表示取补集; -d:delete:表示删除 [root@pc1 test1]# echo "ab,123.cd-458fqq" | tr -dc [[:digit:]] | sed 's/$/\n/' ## 删除所有数字的补集,则剩下数字 123458 [ro 阅读全文
posted @ 2024-02-19 17:37 小鲨鱼2018 阅读(63) 评论(0) 推荐(0)
摘要:001、$RANDOM (0~32767的随机数) a、 [root@pc1 test1]# echo $RANDOM ## 直接输出 31128 [root@pc1 test1]# echo $RANDOM 2539 [root@pc1 test1]# echo $RANDOM 23307 b、限 阅读全文
posted @ 2024-02-19 17:16 小鲨鱼2018 阅读(322) 评论(0) 推荐(0)
摘要:001、方式1 [root@pc1 test1]# awk 'BEGIN{print 10 + 5}' 15 [root@pc1 test1]# awk 'BEGIN{print 10 / 5}' 2 002、方式2 [root@pc1 test1]# echo | awk '{print 10 + 阅读全文
posted @ 2024-02-19 16:56 小鲨鱼2018 阅读(86) 评论(0) 推荐(0)
摘要:001、 [root@pc1 test1]# ls a.txt [root@pc1 test1]# cat a.txt ## 测试文本 33 ff su ii aa kk ff dd sU jj kk ff aa Su ee aa SU kk ff xx ad sk uu ff [root@pc1 阅读全文
posted @ 2024-02-19 15:34 小鲨鱼2018 阅读(90) 评论(0) 推荐(0)
摘要:001、 [root@pc1 test1]# ls a.txt [root@pc1 test1]# cat a.txt ## 测试文本 dd ff iiabcjjj ff aa qq aaabcabcabckk aa abc ff uuu aa abcabcabcabcjj kk uu [root@ 阅读全文
posted @ 2024-02-19 15:29 小鲨鱼2018 阅读(75) 评论(0) 推荐(0)
摘要:0:找到匹配模式 1:未找到匹配模式 2:指定的输入文件不对 001、 [root@pc1 test1]# ls a.txt [root@pc1 test1]# cat a.txt ## 测试文本 aa bb cc 11 aa 33 33 dd bb [root@pc1 test1]# grep " 阅读全文
posted @ 2024-02-19 15:05 小鲨鱼2018 阅读(458) 评论(0) 推荐(0)
摘要:001、while循环:条件满足一直执行 [root@pc1 test1]# i=1 ## 条件满足,一直执行 [root@pc1 test1]# while [[ $i -le 3 ]]; do echo $i; i=$((i+1)); done 1 2 3 002、until循环;条件不满足一直 阅读全文
posted @ 2024-02-19 12:05 小鲨鱼2018 阅读(140) 评论(0) 推荐(0)
摘要:001、for循环:for循环的终止条件在for语句后面已经提前已知 [root@pc1 test1]# for ((i = 1; i <= 3; i++)); do echo $i; done ## 终止条件i <= 3; i的变化规律;提前已知 1 2 3 002、while循环; while循 阅读全文
posted @ 2024-02-19 11:59 小鲨鱼2018 阅读(35) 评论(0) 推荐(0)
摘要:001、-a: 后跟一个变量,该变量会被认为是个数组,然后给其赋值,默认是以空格为分割符。 [root@pc1 test1]# read -a ay1 ## -a数据读入数组变量 aa bb cc 100 800 [root@pc1 test1]# echo $ay1 aa [root@pc1 te 阅读全文
posted @ 2024-02-19 11:23 小鲨鱼2018 阅读(509) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2024-02-19 10:26 小鲨鱼2018 阅读(61) 评论(0) 推荐(0)
摘要:通常更推荐使用双方引号。 001、双方引号可以避免变量的单词分割 [root@pc1 test1]# str1="aa bb" ## 测试字符串 [root@pc1 test1]# if [[ $str1 == "aa bb" ]]; then echo "yes"; fi ## 双边引号不用担心变 阅读全文
posted @ 2024-02-19 09:17 小鲨鱼2018 阅读(26) 评论(0) 推荐(0)
摘要:内部字符单分隔符(Internal Field Separator,IFS) 是一个系统环境变量; 无法使用echo $IFS进行查看 001、查看IFS [root@pc1 test1]# set | grep "^IFS" ## 系统默认的IFS IFS=$' \t\n' [root@pc1 t 阅读全文
posted @ 2024-02-19 09:12 小鲨鱼2018 阅读(106) 评论(2) 推荐(0)
摘要:001、 (base) [b20223040323@admin1 test2]$ ls test.txt (base) [b20223040323@admin1 test2]$ cat test.txt ## 测试数据如下;根据第一列和第三列对数据进行去重复 ID=gene-RIN1 rna-XM_ 阅读全文
posted @ 2024-02-18 10:08 小鲨鱼2018 阅读(128) 评论(0) 推荐(0)
摘要:next 是跳过当前行(awk自身是列循环和行循环的结合); continue是跳过当前循环(跳过列循环); 001、next;跳过当前行 (base) [b20223040323@admin1 test2]$ ls a.txt (base) [b20223040323@admin1 test2]$ 阅读全文
posted @ 2024-02-18 10:05 小鲨鱼2018 阅读(235) 评论(0) 推荐(0)
摘要:001、 (base) [b20223040323@admin1 test2]$ cat 003.txt ## 测试数据如下,第一列有多个项,且部分项有重复,实现根据第三列筛选出最大的项 ID=gene-TRNAC-GCA rna-TRNAC-GCA 72 ID=gene-ATP5O rna-XM_ 阅读全文
posted @ 2024-02-18 09:07 小鲨鱼2018 阅读(324) 评论(0) 推荐(0)
摘要:\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 阅读全文
posted @ 2024-02-17 20:24 小鲨鱼2018 阅读(340) 评论(0) 推荐(0)
摘要: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 ## 最小 阅读全文
posted @ 2024-02-17 15:39 小鲨鱼2018 阅读(311) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2024-02-15 17:51 小鲨鱼2018 阅读(113) 评论(0) 推荐(0)
摘要: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, 阅读全文
posted @ 2024-02-15 17:50 小鲨鱼2018 阅读(42) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2024-02-10 23:32 小鲨鱼2018 阅读(201) 评论(0) 推荐(0)

上一页 1 ··· 8 9 10 11 12 13 14 15 16 ··· 77 下一页