Languages and Scripting
cancel
Showing results for 
Search instead for 
Did you mean: 

Removing a '\" from a flat file

SOLVED
Go to solution
rmueller58
Valued Contributor

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.
4 REPLIES
rmueller58
Valued Contributor

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.

James R. Ferguson
Acclaimed Contributor

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...
Dennis Handly
Acclaimed Contributor
Solution

Re: Removing a '\" from a flat file

sed will do this:
sed -e 's/\\/ /g' file > file.new
Highlighted
James R. Ferguson
Acclaimed Contributor

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...