[英]AWK how to print more than one information and redirect all to a text file
Need help on this I am creatinga script that will analyse a file and want to use Awk to print 2 informations in an output txt file I am able to print the information No one am looking for in my screen but how to print with the same Awk another information (exemple the number of lines of my file analyzed) and output those two information in a file calle test.txt I tried with this code and code erreor : operator expected 在此方面需要帮助,我正在创建一个脚本,该脚本将分析文件,并希望使用Awk在输出txt文件中打印2条信息。我能够打印该信息没有人在我的屏幕上寻找内容,但是如何使用同一Awk打印另一个信息(例如,我分析的文件的行数),并将这两个信息输出到我使用此代码和erreor代码尝试过的文件teste.txt中:操作员期望
#!/usr/bin/perl
if ($#ARGV ==-1)
{
print "Saisissez un nom de fichier a nalyser \n";
}
else
{
$fname = $ARGV[0];
open(FILE, $fname) || die ("cant open \n");
}
while($ligne=<FILE>)
{
chop ($ligne);
my ($elemnt1, $ellement2, $element3) = split (/ /, $ligne_);
}
system("awk '{print \$2 > "test.txt"}' $fname");
Try escaping the quotes on your last line, so test.txt
is actually in the string passed to system
. 尝试转义最后一行的引号,因此
test.txt
实际上在传递给system
的字符串中。
system("awk '{print \$2 > \"test.txt\"}' $fname");
The Awk variable NR
ends up holding the number of lines in the input while the END
rule is executing. 在执行
END
规则时,Awk变量NR
最终将保持输入中的行数。 Try this: 尝试这个:
$outfile = '"test.txt"';
system("awk '{print \$2 > $outfile} END {print NR > $outfile}' $fname");
Notes: 笔记:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.