in reply to Simple perl one-liner for transforming text files

perl -n000 -e" s[name: ([^\n]+)\ndate: ([^\n]+)\n.*][$1 $2]; chomp; pr +int qq[$_\n]; " <file >newfile

Use 's instead of "s on linux etc.


Examine what is said, not who speaks.
1) When a distinguished but elderly scientist states that something is possible, he is almost certainly right. When he states that something is impossible, he is very probably wrong.
2) The only way of discovering the limits of the possible is to venture a little way past them into the impossible
3) Any sufficiently advanced technology is indistinguishable from magic.
Arthur C. Clarke.

Replies are listed 'Best First'.
Re: Re: Simple perl one-liner for transforming text files
by jdporter (Paladin) on Mar 06, 2003 at 06:22 UTC
    Way too verbose! ;-)
    perl -n000 -pe "$_=qq(@{{/(.*?): (.*)/g}}{name,date}\n)"

    jdporter
    The 6th Rule of Perl Club is -- There is no Rule #6.

      Sorry, I wasn't wearing my golf shoes:^)

      jdporter++. I physically applauded that once I stared at it long enough to work out how the hell it worked.


      Examine what is said, not who speaks.
      1) When a distinguished but elderly scientist states that something is possible, he is almost certainly right. When he states that something is impossible, he is very probably wrong.
      2) The only way of discovering the limits of the possible is to venture a little way past them into the impossible
      3) Any sufficiently advanced technology is indistinguishable from magic.
      Arthur C. Clarke.
Re: Re: Simple perl one-liner for transforming text files
by m5m5m (Initiate) on Mar 05, 2003 at 21:09 UTC
    Very cool. After a bit of reading, I think I understand what you are doing... Does not seem to work for me (prints out every line) yet, maybe I mistyped something... Let me go through it again... Thanks !

      A quick example of it in operation.

      C:\test>type junk name: url1.domain1.com date: 2004/2/1 unwanted info: blah blah blah name: url2.domain5.org date: 2004/3/12 unwanted info: blah blah blah name: url1.domain1.com date: 2004/2/1 unwanted info: blah blah blah name: url2.domain5.org date: 2004/3/12 unwanted info: blah blah blah name: url1.domain1.com date: 2004/2/1 unwanted info: blah blah blah name: url2.domain5.org date: 2004/3/12 unwanted info: blah blah blah name: url1.domain1.com date: 2004/2/1 unwanted info: blah blah blah name: url2.domain5.org date: 2004/3/12 unwanted info: blah blah blah C:\test>perl -n000 -e" s[name: ([^\n]+)\ndate: ([^\n]+)\n.*][$1 $2]; c +homp; print qq[$_\n]; " <junk url1.domain1.com 2004/2/1 url2.domain5.org 2004/3/12 url1.domain1.com 2004/2/1 url2.domain5.org 2004/3/12 url1.domain1.com 2004/2/1 url2.domain5.org 2004/3/12 url1.domain1.com 2004/2/1 url2.domain5.org 2004/3/12 C:\test>

      Examine what is said, not who speaks.
      1) When a distinguished but elderly scientist states that something is possible, he is almost certainly right. When he states that something is impossible, he is very probably wrong.
      2) The only way of discovering the limits of the possible is to venture a little way past them into the impossible
      3) Any sufficiently advanced technology is indistinguishable from magic.
      Arthur C. Clarke.