Linux 中awk命令同时指定多个输出分隔符

 

001、

[root@PC1 test2]# ls
a.txt
[root@PC1 test2]# cat a.txt
./KVC/267189.chr13.error
./KVC/267182.chr6.error
./KVC/267183.chr7.error
./MGH/267281.chr26.error
./KKY/267049.chr4.error
./KRD/267095.chr24.error
./HRK/267038.chr19.error
./AFS/266639.chr10.error
./ARQ/266712.chr5.error
./ARQ/266724.chr17.error
./ARQ/266728.chr21.error
./SNB/267451.chr22.error
[root@PC1 test2]# awk 'BEGIN{FS="[./]"}{print $3, $5}' a.txt | head -n 3      ## 普通正则表达式, 匹配[]中的任一个字符 
KVC chr13
KVC chr6
KVC chr7
[root@PC1 test2]# awk 'BEGIN{FS="\\.|/|\\.chr"}{print $5}' a.txt | head -n 3    ##  多字符分隔符.chr,需要用到或 |; 其中.需要双重转义
13
6
7

image

 。

 

posted @ 2026-06-23 15:19  小鲨鱼2018  阅读(5)  评论(0)    收藏  举报