简体   繁体   English

在while循环中使用awk命令的问题

[英]Issue with awk command inside while loop

I have a problem with this awk command because after the first iteration of the while loop, the information is written in the same line as the first iteration instead of written in the row where the value is found. 我对这个awk命令有问题,因为在while循环的第一次迭代之后,信息被写入与第一次迭代相同的行中,而不是写在找到值的行中。

while read list
do
    awk -v M="$Variable" -v R="Fail" -v J="Sorry, but this fail" -v K="N/A"  '
        BEGIN {FS=","; OFS=","}
        $1==M {$14=R; $21=J; $22=K; print}
        $1 != M ' file.csv > file2.csv
done < list.csv

I think instead of file.csv > file2.csv you'll need file.csv >> file2.csv . 我认为不是file.csv > file2.csv而是需要file.csv >> file2.csv The > will overwrite file2.csv , and the >> will append to it. >将覆盖file2.csv ,并且>>将追加到该文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM