add - (minus) in front of a column with value condition of another column
Hello all,
I need some help with a csv file. My file looks like: ACL,0,2,1,1,1,0,0 ACL,1,3,2,0,1,0,0 ACL,2,6,2,1,1,0,0 ACL,3,1,1,0,0,1000,0 How I can add - (minus) in front of column 3 if column 5==1 Desired result: ACL,0,-2,1,1,1,0,0 ACL,1,3,2,0,1,0,0 ACL,2,-6,2,1,1,0,0 ACL,3,1,1,0,0,1000,0 Thanks |
Please use ***[code][/code]*** tags around your code and data, to preserve the original formatting and to improve readability. Do not use quote tags, bolding, colors, "start/end" lines, or other creative techniques.
This is a perfect job for awk. Code:
$ awk -F, -v OFS=, '$5 == 1 { $3 = -$3 }1' file.txt |
All times are GMT -5. The time now is 10:45 PM. |