0

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.

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
2
  • It's not clear what you want. Your code clearly overwrites file2.csv as many times as there are lines in list.csv but you have not explained why it's doing this, or how the files are related. Do you just want to loop over lines in file.csv? Then the while loop is superfluous. Does list.csv contain names of files to process? Then the loop should use the value in $list for something, such as the input file name for Awk. Commented May 31, 2015 at 4:27
  • This problem may be easier to understand (and solve) if you gave sample of your input. See How to Ask. Commented May 31, 2015 at 17:22

1 Answer 1

2

I think instead of file.csv > file2.csv you'll need file.csv >> file2.csv. The > will overwrite file2.csv, and the >> will append to it.

Sign up to request clarification or add additional context in comments.

2 Comments

the issue is if i do that i have so much information duplicated in the file2.csv that i dont wish, because it add me other row, and i need overwrite the information , no adds more information
If i do (file.csv >> file2.csv) i will have the file2.csv with two lines duplicated<br/>For example in this file :<br/>column1 column14 column21 column22<br/>usb 1 fail Sorry but this fail N/A <br/>usb2<br/>usb 1 fail Sorry but this fail N/A

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.