Languages and Scripting
Showing results for 
Search instead for 
Do you mean 

Removing a '\" from a flat file

SOLVED
Go to Solution
Valued Contributor 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.
1 ACCEPTED SOLUTIONS
Acclaimed Contributor Acclaimed Contributor

Re: Removing a '\" from a flat file

sed will do this:
sed -e 's/\\/ /g' file > file.new
4 REPLIES
Valued Contributor 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.

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

Re: Removing a '\" from a flat file

sed will do this:
sed -e 's/\\/ /g' file > file.new
Highlighted
Acclaimed Contributor 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...