Discussion Locked

Replace special characters in feed file

0 helpful
3 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Hi,
I have a flat file that I am trying to load into Oracle 8i db. The file contains special characters for quotes:
eg. doesn?t instead of doesn't

How can I replace all the special characters with quotes so it loads correctly in oracle and shows up correctly on my web site.

Any help is greatly appretiated.

Thanks.

3 replies

by cpfeiffe

sed is a great tool for this sort of thing. However before using sed you are making an assumption that you want to replace every /E with '. If that is true you can do it with a one liner as will be given in my example. If that is not true you canadd options to sed to look at certain lines and mix it with cut or awk/gawk/nawk. That gets pretty nasty if you never used any of these tools before. Once you get this one done you can re-edit the file with sed (stands for streamline editor) to change others or you can do multiples on one line with the -e option. That can get pretty nasty too and I would recommend doing one replacement at a time and checking it before proceeding.

Here is the example:
sed 's/\/E/'/g' file > newfile

This will execute sed to substitute every occurance of /E with ' in file and redirect the result to newfile. You can then check newfile and if it is good move/copy it back to file. The general syntax for sed substitution is sed 's/pattern to replace/replace with/' file. The \ escapes the / before the E so it is read as a character / and not part of the sed argument. The g says global (entire file) instead of just the first occurance of the pattern. The > newfile sends the output to newfile instead of STDOUT.

Hope this helps. Good luck.

This discussion is closed to new replies.