[英]how to use loop in awk
I use the following command to extract 2nd column from table1.txt
and get output as output1.txt
我使用以下命令从
table1.txt
提取第二列,并输出为output1.txt
awk '{ print $2 }' table.txt > output.txt
How to use loop for five files ( table.txt
, abc.txt
, pqr.txt
, skt.txt
, mkt.txt
) to extract 2nd column in respective output files ( out_table.txt
, out_abc.txt
, out_pqr.txt
, out_skt.txt
, out_mkt.txt
) ? 如何使用五个文件(
table.txt
, abc.txt
, pqr.txt
, skt.txt
, mkt.txt
)的mkt.txt
来提取各个输出文件( out_table.txt
, out_abc.txt
, out_pqr.txt
, out_skt.txt
)中的第二列out_skt.txt
, out_mkt.txt
)?
you don't need to write a loop in awk. 您无需在awk中编写循环。 You could use the build-in variable
FILENAME
: 您可以使用内置变量
FILENAME
:
awk '{print $2 > "out_"FILENAME".txt"}' table.txt abc.txt pqr.txt skt.txt mkt.txt
使用FILENAME
变量将相应的输出文件名用于输入一个:
awk '{ print $2 > "out_" FILENAME }' *.txt
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.