Operating System - HP-UX
1849977 Members
1939 Online
104049 Solutions
New Discussion

Re: Search and replace control chars

 
Fidel Ramirez_1
Frequent Advisor

Search and replace control chars

An application creates a multipage print file. There is a new page control character when starting a new page. I want to add a new line right after this new page character.
On vi, I see this char as ^L. If I edit the file interactively with vi, I’m able to create a new line with a global find and substitution like this
:g/^L/s//^L^M/
But when try doing the same on a shell script, it fails.
Using od –cb, ^L is displayed as \f and 014 octal.
Any hints why this is failing on any script type to add a new line after this control character?
3 REPLIES 3
James R. Ferguson
Acclaimed Contributor

Re: Search and replace control chars

Hi Fidel:

# perl -pi -e 's/\014/\014\012/g' file

...will update the file inplace.

The ^M you show is really a carriage-return character (\015). If you truly want that, change the \012 to a \015 in the above, although properly, it should a \015 followed by a \012.

Regards!

...JRF...
Fidel Ramirez_1
Frequent Advisor

Re: Search and replace control chars

Sweet!

Thanks for your nice reply.
Dennis Handly
Acclaimed Contributor

Re: Search and replace control chars

:g/^L/s//^L^M/
>But when try doing the same on a shell script, it fails.

How are you doing it in a script? With sed?

>Using od â cb, ^L is displayed as \f and 014 octal.

Yes, that's a formfeed.

>Any hints why this is failing on any script type to add a new line after this control character?

I've mentioned before that I can't enter a CR in the shell, only a linefeed. In vi, I can use control-V control-M and get it. Perhaps that's your issue?