[英]Print Specific Columns using AWK
I'm trying to fetch the data from column B to D from a tab delimited file "FILE". 我正在尝试从制表符分隔的文件“ FILE”中将数据从B列提取到D列。 The simple AWK code I use fetch the data, but unfortunately keeps the output in a single column and remove the identifiers (shown below). 我使用的简单AWK代码获取数据,但不幸的是,将输出保留在单个列中并删除了标识符(如下所示)。
Any suggestions please. 有任何建议请。
CODE 码
awk '{for(i=2;i<=4;++i)print $i}' FILE
FILE 文件
A B C D E F G
1_at 10.8435630935 10.8559287854 8.6666141543 8.820310681 9.9024050571 8.613199083 11.9807771094
2_at 4.7615531106 4.5209119307 11.2467919586 8.8105151099 7.1831990104 11.0645055836 4.3726598561
3_at 6.0025262754 5.4058080843 3.2475272982 3.1869728585 3.5654989547
OUTPUT OBTAINED 获得的输出
B
C
D
10.8435630935
10.8559287854
8.6666141543
4.7615531106
4.5209119307
11.2467919586
6.0025262754
5.4058080843
3.2475272982
Why don't you directly use cut
? 为什么不直接使用cut
?
$ cut -d$'\t' -f2-4 < file
B C D
10.8435630935 10.8559287854 8.6666141543
4.7615531106 4.5209119307 11.2467919586
6.0025262754 5.4058080843 3.2475272982
With awk
you would need printf
to avoid new lines of print
: 使用awk
您将需要printf
以避免出现新的print
行:
awk -F"\t" '{for(i=2;i<=4;++i) printf "%s%s", $i, (i==4?RS:FS)}'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.