我有一个文件,它是几个管道命令的输出。像这样的东西
command1 input.txt| command2 | command3 | input file
该文件以制表符分隔
命令 3 之后,我的输入文件如下所示
chr6 116732135 116741866 116732135 116732368 116741505 116741866 + 0.79 0.51 0.97 0.77 0.48 0.97 0.02 0.37 'chr6:116732136-116732368:+@chr6:116741506-116741866:+.A.withRI','chr6:116732136-116732368:+@chr6:116741506-116741866:+.B.up_chr6:116732136-116732368:+@chr6:116741506-116741866:+.B.dn' (0,0):10,(1,0):147,(1,1):1 0:148 (0,0):36,(1,0):161,(1,1):3 0:163,1:1 chr6 + 116732136,116732136 116741866,116741866 gene_id "ENSG00000196911.10"; transcript_id "ENST00000368564.6"; gene_type "protein_coding"; gene_name "KPNA5"; transcript_type "protein_coding"; transcript_name "KPNA5-202"; level 2; protein_id "ENSP00000357552.1"; transcript_support_level "1"; tag "basic"; tag "appris_principal_1"; tag "CCDS"; ccdsid "CCDS5111.1"; havana_gene "OTTHUMG00000015448.4"; havana_transcript "OTTHUMT00000041967.2";
chr6 116732135 116741866 116732135 116732368 116741505 116741866 + 0.79 0.51 0.97 0.77 0.48 0.97 0.02 0.37 'chr6:116732136-116732368:+@chr6:116741506-116741866:+.A.withRI','chr6:116732136-116732368:+@chr6:116741506-116741866:+.B.up_chr6:116732136-116732368:+@chr6:116741506-116741866:+.B.dn' (0,0):10,(1,0):147,(1,1):1 0:148 (0,0):36,(1,0):161,(1,1):3 0:163,1:1 chr6 + 116732136,116732136 116741866,116741866 gene_id "ENSG00000196911.10"; transcript_id "ENST00000356348.6"; gene_type "protein_coding"; gene_name "KPNA5"; transcript_type "protein_coding"; transcript_name "KPNA5-201"; level 2; protein_id "ENSP00000348704.1"; transcript_support_level "1"; tag "basic"; tag "appris_principal_1"; tag "CCDS"; ccdsid "CCDS5111.1"; havana_gene "OTTHUMG00000015448.4"; havana_transcript "OTTHUMT00000041969.2";
在命令 3 之后,我使用 awk 命令拆分最后一列使用;
This is the command
command1 input.txt| command2 | command3 | awk -F "\t" -v OFS="\t" '{split($NF,a,";"); $NF=""; print $0,a[1],a[4]}'
我想拆分从 command3 获得的文件的最后一个字段,然后打印除最后一个字段之外的所有字段,然后打印拆分字段 a[1] 和 a[4],但这会在第 1-25 列和第 1-25 列之间添加一个选项卡一个[1],一个[4]。我怎样才能避免这种情况?
谢谢
这是输出
chr6 116732135 116741866 116732135 116732368 116741505 116741866 + 0.79 0.51 0.97 0.77 0.48 0.97 0.02 0.37 'chr6:116732136-116732368:+@chr6:116741506-116741866:+.A.withRI','chr6:116732136-116732368:+@chr6:116741506-116741866:+.B.up_chr6:116732136-116732368:+@chr6:116741506-116741866:+.B.dn' (0,0):10,(1,0):147,(1,1):1 0:148 (0,0):36,(1,0):161,(1,1):3 0:163,1:1 chr6 + 116732136,116732136 116741866,116741866 gene_id "ENSG00000196911.10" gene_name "KPNA5"
chr6 116732135 116741866 116732135 116732368 116741505 116741866 + 0.79 0.51 0.97 0.77 0.48 0.97 0.02 0.37 'chr6:116732136-116732368:+@chr6:116741506-116741866:+.A.withRI','chr6:116732136-116732368:+@chr6:116741506-116741866:+.B.up_chr6:116732136-116732368:+@chr6:116741506-116741866:+.B.dn' (0,0):10,(1,0):147,(1,1):1 0:148 (0,0):36,(1,0):161,(1,1):3 0:163,1:1 chr6 + 116732136,116732136 116741866,116741866 gene_id "ENSG00000196911.10" gene_name "KPNA5"
所以,鉴于
(我
cat -A
用来显示选项卡^I
以便于可视化的地方)您想消除双选项卡吗?如果是这样,一种方法是递减
NF
而不是将空字符串分配给$NF
:另一种方法是连接字符串而不是将它们打印为字段 - 您可以通过删除
,
它们之间的字符串来实现: