linux 中实现提取排除指定系列字符串以外的数据

 

001、

(base) [b20223040323@admin1 test]$ ls
a.txt  b.txt
(base) [b20223040323@admin1 test]$ cat a.txt        ## 测试数据
GENE=3BHSD      1       1
GENE=A3GALT2    1       1
GENE=A1BG       1       1
GENE=AAAS       1       1
GENE=A1CF       1       1
GENE=A2M        0       0
(base) [b20223040323@admin1 test]$ cat b.txt         ## 测试数据
GENE=3BHSD
GENE=A1BG
GENE=A1CF
(base) [b20223040323@admin1 test]$ cp a.txt a.txt_bak      ## 对要在源文件中修改的文件进行备份,防止出现意外
(base) [b20223040323@admin1 test]$ for i in $(cat b.txt ); do sed -i "/$i/d" a.txt; done  ## 利用循环结构,sed删除匹配字符串的行
(base) [b20223040323@admin1 test]$ ls
a.txt  a.txt_bak  b.txt
(base) [b20223040323@admin1 test]$ cat a.txt    ## 修改后的结果
GENE=A3GALT2    1       1
GENE=AAAS       1       1
GENE=A2M        0       0

 

posted @ 2023-03-16 16:35  小鲨鱼2018  阅读(63)  评论(0编辑  收藏  举报