Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have a folder full of files, each with many hundreds of lines. Many of these files have occasional broken newlines: when I open them in vim, many have ^M^L interspersed where newlines should be.

In vim, I can run %s/^M^L/\r/g which will correct them. However, I don't want to have to do this to every file.

So I'm trying to do this in a bash script via sed, but it hasn't worked. I've tried both:

sed 's/^M^L/\r/g' filename and

sed 's/^M^L/\
/g' filename

Note: each time ^M^L appears here, I have done ctrl-v ctrl-m, not just shift-6 (^) M.

What am I doing wrong? More to the point, what do I need to do for this to work?

share|improve this question
    
linux - I'm not sure which distribution the server has installed. I could find that out if it is important. –  David Oneill Feb 28 '12 at 15:32
    
No. That gives me what I need. See below. –  Karlson Feb 28 '12 at 15:41
add comment

1 Answer

up vote 3 down vote accepted

You should be able to do:

sed 's/\x0C//g`

or

sed 's/\x0D\x0C/\x0D/g'

or if you using GNU sed

sed 's/\r\f/\r/'
share|improve this answer
    
For posterity: I had to actually use sed 's/\x0C/\x0A/g` since these files were DOS formatted. I hadn't noticed that until I was trying Karlson's answer. Thanks! +1 –  David Oneill Feb 28 '12 at 18:07
    
Replacing page breaks with \n? –  Karlson Feb 28 '12 at 18:09
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.