tags:

views:

161

answers:

1

I'm trying to strip some content from an HTML file automatically, and I'm using the following command to strip everything up to the useful data:

perl -pi.bak -e 'undef $/; s/^.*?<pre>//s' $file

However, for some reason this leaves the first line of the HTML file (the DOCTYPE declaration) alone.

+12  A: 

By the time you undef $/, the first line has already been read. Use the -0 option to set $/ before anything has been read.

perl -p0i.bak -e 's/^.*?<pre>//s'
Chris Johnsen
Supposing that the `-0` switch wasn't there you could do `-e 'BEGIN { undef $/ } s/^.*?<pre>//s'`.
hobbs
Yes, a `BEGIN` can also do the work early enough.
Chris Johnsen