Text manipulation using sed
I have a number of text files (26 per database x 100+ databases) which need 'correcting' in order to import into postgresql.
I think that I have identified all the problem characters and I need to automate the process as much as possible. I have a script to convert the characters and I do them one by one (not effecient but easier to understand). What I cannot understand is why some conversions work in the script : eg : sed 's/|/","/g' < file.in > file.out sed 's/$/");/' < file1.in > file2.out but others will not : eg sed 's/"/-/g If I vi the individual data file, I can use the following : eg :%s/"/-/g or :%s'/'-'g and these work. My problem characters are 1. ' to - (:%s/'/-/g) 2. " to - (:%s/"/-/g) 3. / to - (:%s'/'-'g) 4. \ to (:%s'\' 'g) 5. \\ to -(:%s'/\\'-'g) 6. ` to - (:%s/`/-/g) 7. & to a (:%s/&/a/g) 8. @ to a (:%s/@/a/g) |
Maybe it depends from the order by which it makes substitutions. For example you have to change \\ before \ otherwise the former will become -\. Regarding the syntax I checked and the following works for me:
Code:
sed "s/'/-/" |
How about placing each group into a variable and then character class:
Code:
change_dash="\"'\`/" |
All times are GMT -5. The time now is 10:20 AM. |