Awk sub command - Prod - Urgent

Hi

I have this check in file for replacing text in unix .This code use to work in linux but stopped working when we moved to unix.

cat xyz.dat | awk '/\x07/{sub(/\"/,"")};{print}'|awk '/\x07/{sub(/\"\,\"/,"\x07")};{print}'|awk '/\x07/{sub(/\"\,\"/,"\x07")};{print}'|awk '/\x07/{sub(/\"\,\"/,"\x07")};{print}'| dos2unix > abc.dat

If you notice
awk '/\x07/{sub(/\"/,"")};{print}'
This command is repated

How can I fix that?

What command should I use awk in Unix so that I get desired result

Quick response appreciated.

what are you trying to accomplish? can you post sample input and output? Please use code tags when posting code or sample i/oput.
Furthermore, is there any error? What exactly is your system?

Use nawk if on Solaris.

i want to replace string ,", with octal value 007 (^G)

My file is in format .there are 5 column

"col1","col2","col3","col4","col5"

is should appear like this

col1^Gcol2^Gcol3^Gcol4^Gcol5.

Error I get

awk : Syntax error at line 1
awk : illegal statement near line 1

And your system is... ?

Try this instead:

cat xyz.dat | sed 's/","/\x07/g ; s/"//g'

SYSTEM IS SUNOS SPARC

---------- Post updated at 05:15 PM ---------- Previous update was at 05:12 PM ----------

what if i get " in my data.

this wont work

my script use to take care of it
but it doesn't work on Unix

not able to figure out why

cat xyz.dat | nawk '{gsub(/","/,"\x007"); gsub(/"/,"")}1'

---------- Post updated at 02:19 PM ---------- Previous update was at 02:15 PM ----------

If you are worried about quotes inside the fields, you can use anchors to strip just the first and last:

cat xyz.dat |  sed 's/","/\x07/g ; s/^"// ; s/"$//'

but it's a mess that could be cleaned up, for maintanence sake if for nothing else.

Sorry... I realize you are frustrated and stressed out because of the situation...

Just replace "awk" with "nawk" or "/usr/xpg4/bin/awk" and your old script should run fine.

1 Like