[GRLUG] perl, sed or tr (insert page break)

Al Tobey tobert at gmail.com
Tue Jan 23 00:01:30 EST 2007


On 1/22/07, Godwin <geektoyz at gmail.com> wrote:
> ...so in a file, I'd like to look for a pattern then preceed the pattern by
> a page break.
>
> Ex.  pattern line begins with " 050 " (spaces included)
>
> tr "^ 050" "\f" < filein > fileout    # Didn't work
> sed -e 's/^\ 050/\f\ 050\ /g' filein > fileout   # Didn't work either

I don't think you need to escape the spaces if the regex is quoted
properly.   If you want to accept any whitespace, use the character
class, [:space:].   You also don't need the 'g' modifier since you're
anchoring to the front of the line anyways.

sed -e 's/^ 050/\f 050 /' filein > fileout
sed -e 's/^[[:space:]]050/\f 050/' filein > fileout

> haven't tried Perl...

There really isn't any advantage to going to perl unless you're doing
more than a simple transform.  Sometimes perl is a little faster on
large files because it does its own buffering, but YMMV.

perl -pe 's/^[[:space:]]050/\f 050/' < filein > fileout
perl -pe 's/^\s050/\f 050/' < filein > fileout

> Any thoughts!

man 7 regex
perldoc perlre

I've found that the regex manpage on HP-UX is actually quite a bit
better than the GNU one.    I learned a lot about standard regular
expressions from the HP-UX manpage when writing some logsurfer configs
from scratch years ago.

-Al

>
> thanks,
> G-
>
> --
>
> Ubber::Geek
>  http://grlug.org/
> _______________________________________________
> grlug mailing list
> grlug at grlug.org
> http://shinobu.grlug.org/cgi-bin/mailman/listinfo/grlug
>
>


More information about the grlug mailing list