Re: Removing a '\" from a flat file (98 Views)
Reply
Valued Contributor
rmueller58
Posts: 851
Registered: ‎02-19-2001
Message 1 of 5 (98 Views)
Accepted Solution

Removing a '\" from a flat file

I have an Informix SQL script that dumps data to a flat, CSV file.

Informix placed a "\" in null fields. I'd appreciate any pointers on how to either fix the SQL script, or script a perl substitution that yanks the "\" and replaces it with a space.
Valued Contributor
rmueller58
Posts: 851
Registered: ‎02-19-2001
Message 2 of 5 (98 Views)

Re: Removing a '\" from a flat file

space or nothing

I thought initially I could do

perl -pi -e s/'\'//g filename.csv

I get the following error:

# perl -pi -e s/'\'//g ralalertnow.csv
Substitution replacement not terminated at -e line 1.

Acclaimed Contributor
James R. Ferguson
Posts: 21,184
Registered: ‎07-06-2000
Message 3 of 5 (98 Views)

Re: Removing a '\" from a flat file

Hi:

# perl -pe 's/"\\"/" "/g' file

...and if you want to update "in-place":

# perl -pi.old -e 's/"\\"/" "/g' file

...which preserves the original file as "file.old".

Regards!

...JRF...
Acclaimed Contributor
Dennis Handly
Posts: 25,198
Registered: ‎03-06-2006
Message 4 of 5 (98 Views)

Re: Removing a '\" from a flat file

sed will do this:
sed -e 's/\\/ /g' file > file.new
Acclaimed Contributor
James R. Ferguson
Posts: 21,184
Registered: ‎07-06-2000
Message 5 of 5 (98 Views)

Re: Removing a '\" from a flat file

Hi (again):

> I tried the perl version and it failed to string the '\' Dennis's sed script worked..

Yes, Dennis's script blindly replaces ALL backslashes with spaces. Is that what you really want?

You didn't make that very clear in my opinion. I replaced only "\" by " ".

Regards!

...JRF...
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.