I have a file (file1) with millions of rows and columns. An example of data are:
"col1","col2","col3","col4","col5","col6""AAA",0,5,10,"BGB",50"BBB",4,7,10,"BFD",76"AAA",15,0,0,"BGB",20"AAA",10,13,10,"DDD",23
I want to find all lines that have AAA in col1 and then get all the rows that have BGB in col5. And finally, decrease 50% of every value in col2, col3, col4, and col6 (Ignore if cell values are 0 or blank). And print all the lines of the file. So, my output will look like following:
"col1","col2","col3","col4","col5","col6""AAA",0,2.5,5,"BGB",25"BBB",4,7,10,"BFD",76"AAA",7.5,0,0,"BGB",10"AAA",10,13,10,"DDD",23
I have been trying the following, but could not make it work (also, could not figure out how to use multiple columns in gsub)
grep AAA file1 | awk -F "," '$5~/BGB/ {gsub($6,\substr($6,1,length($6)-1)*0.50\, $6}1'