in reply to Re: elementary hash
in thread elementary hash, STDIN questions

Here's a fun one-liner:

perl -pi.bak -e 's/(^\s+$)?|blahblah|wahwah|yadayada//g' <filename>

If you run it twice, it'll squash blank lines. The regex could be more robust, but I hadn't seen any one-liner yet.

Update: I still don't understand tilly's followup, but let me explain what I mean a little further. My one-liner strips out the words mentioned above, but retains the line-ending newlines. tilly's dual-regex below fixes that. If you run mine twice, it'll get rid of the newlines (as the first part of the regex squashes whitespace). It has the (unlikely) side effect of getting rid of a string that, in the original file, would resemble 'blahyadayadablah'.

Not that you should be doing this with a one-liner.... :)

Replies are listed 'Best First'.
RE (tilly) 3: elementary hash
by tilly (Archbishop) on Sep 12, 2000 at 04:10 UTC
    Actually that doesn't match the original code. If the entire text of the original was one of the matches, then it should be squashed. Here is a one-liner that works and is shorter, but only because of what the strings are:
    perl -pi.bak -e 's/(blah|wah|yada)\1//g;s/^\s+$//' $file