001、将ab替换为QQ
(base) [b20223040323@admin2 test2]$ ls a.txt (base) [b20223040323@admin2 test2]$ cat a.txt ## 测试数据 snp1 ab 1072 0 snp4 abde 392 0 snp5 ab 401 0 snp6 eabx 1223 0 snp7 cxab 1260 0 (base) [b20223040323@admin2 test2]$ sed 's/ab/QQ/g' a.txt ## 所有匹配的ab均被替换为QQ snp1 QQ 1072 0 snp4 QQde 392 0 snp5 QQ 401 0 snp6 eQQx 1223 0 snp7 cxQQ 1260 0
02、只将第二列为单个的ab替换为QQ
(base) [b20223040323@admin2 test2]$ ls a.txt (base) [b20223040323@admin2 test2]$ cat a.txt snp1 ab 1072 0 snp4 abde 392 0 snp5 ab 401 0 snp6 eabx 1223 0 snp7 cxab 1260 0 (base) [b20223040323@admin2 test2]$ sed 's/\sab\s/\tQQ\t/g' a.txt ## 对第二列ab的精确替换 snp1 QQ 1072 0 snp4 abde 392 0 snp5 QQ 401 0 snp6 eabx 1223 0 snp7 cxab 1260 0
标签:QQ,admin2,test2,sed,base,linux,txt,ab,替换 From: https://www.cnblogs.com/liujiaxin2018/p/17289061.html