Operating System - Linux
1825810 Members
3101 Online
109688 Solutions
New Discussion

replacing special characters with sed

 
SOLVED
Go to solution
Scott Guy_2
Advisor

replacing special characters with sed

I'm befuddled!!!

I have a file that I'm having issues with special characters. Each new "entry" in the file begins with a ^M^L (when viewed in vi). For some reason, every now and then, there is an extra ^M^L, so the line starts with ^M^L^M^L I don't need the second sequence.

I tried using sed as follows:
sed s/^M^L^M^L/^M^L/g file1 > file2

That isn't working. Any pointers??

Scott
6 REPLIES 6
Oviwan
Honored Contributor

Re: replacing special characters with sed

Hey

Check dos2ux:

#dos2ux file > file2

hope this works

Regards
James R. Ferguson
Acclaimed Contributor

Re: replacing special characters with sed

Hi Scott:

# perl -pe 's/^\015\014\015\014/\015\014/' file

...or to update in-place:

# perl -pi.old -e 's/^\015\014\015\014/\015\014/' file

...which will preserve a copy of "file" as "file.old".

Regards!

...JRF...
Sandman!
Honored Contributor
Solution

Re: replacing special characters with sed

How did you type in the control characters? Hold down Ctrl-V then type M to get ^M. Similarly to get ^L hold down Ctrl-V and then type L i.e.

sed 's///g' infile
Scott Guy_2
Advisor

Re: replacing special characters with sed

That was exactly it Sandman.

Thanks to everyone for their assistance.
Scott Guy_2
Advisor

Re: replacing special characters with sed

Question answered by replies
Dennis Handly
Acclaimed Contributor

Re: replacing special characters with sed

>That was exactly it Sandman.

The last time there was a thread about ^M, there was no way to enter it in a real shell but you could enter it in vi.

Did you have any problems in a shell?