Skip to main content
Tweeted twitter.com/StackUnix/status/1011344508603240449
edited tags
Link
Jeff Schaller
  • 68.8k
  • 35
  • 122
  • 266
Source Link
SSDdude
  • 171
  • 2
  • 13

search column 2 in csv file for value, if value, then insert "invalid" and shift cells right

I have csv file that is auto generated by a script but for some of the records (line items) received I need to search column 2 and if the values contains "*.app" I need to print "INVALID" into column 2 for all records matching and shift cells to the right.

Example Data File:

 DOM,PROJ,APP,USER,DATE,TIME,STATUS www,test,biz.app,bob,6-1-18,09:33,OK //Example of good line www,biz.app,tony,7-11-17,06:22,ok //Example of bad line ... Wanted output: DOM,PROJ,APP,USER,DATE,TIME,STATUS www,test,biz.app,bob,6-1-18,09:33,OK www,INVALID,biz.app,tony,7-11-17,06:22,ok //Example of fixed line ... 

I have unsuccessfully tried awk, sed, and if statement but not getting the results I need

 e.g. if [ awk -F',' '{ print $2 } < FILE' ] == "*.app" ; then ; echo "INVALID"; fi 

Which is obviously terrible... New to bash thanks all!