awk removes delimiter unexpectedly

datafile:

blah,blah,blah,blah,blah,blah,blah,blah,blah=0_nblah=0-- ,blah,blah,blah

im using the following command to turn the "_n" and "-- " to just a space " " only in the $9th field. meaning, it has to make the changes only in the 9th column/field of the datafile.

awk -F, '{ gsub(/_n/, " ", $9) ; gsub(/-- /, " ", $9) }1' datafile

but the resulting output gets rid of my delimiters:

blah blah blah blah blah blah blah blah blah=0 blah=0 blah blah blah

i want the resulting output to be:

blah,blah,blah,blah,blah,blah,blah,blah,blah=0 blah=0,blah,blah,blah

shell: /bin/sh
OS: all unix flavors. mainly linux

Hello SkySmart,

Could you please run following and let me know if this helps.

awk -F, '{sub(/_n/," ",$9);sub(/-- /,"",$9)} 1' OFS=,  Input_file

Output will be as follows.

blah,blah,blah,blah,blah,blah,blah,blah,blah=0 blah=0,blah,blah,blah

Thanks,
R. Singh

1 Like