Quantcast
Channel: Active questions tagged windows-subsystem-for-linux - Ask Ubuntu
Viewing all articles
Browse latest Browse all 2825

modify specific columns based on another column by using awk and gsub

$
0
0

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'

Viewing all articles
Browse latest Browse all 2825

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>