Linux 中awk命令同时指定多个分割符

小鲨鱼2018 / 2024-09-25 / 原文

 

001、

[root@localhost test]# ls
a.txt
[root@localhost test]# cat a.txt                               ## 测试数据
aadd kk;gene=ABEK:ett 8735
fdfk jj;gene=IYNF:34DF UYG
[root@localhost test]# awk -F "[gene=|:]" '{print $2}' a.txt       ## 使用-F 参数无法对分割符包含多个字符的情况进行处理


[root@localhost test]# awk -F "[gene=:]" '{print $2}' a.txt


[root@localhost test]# awk  'BEGIN{FS="gene=|:"} {print $2}' a.txt        ## 可以使用内部变量FS实现
ABEK
IYNF

。