http://qs321.pair.com?node_id=240789


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

Here's another version. When running one-liners it is extremely useful to learn the command line operators. Here's a short breakdown:

 perl -al0nF: -e 'print /name/&&++$x,/name|date/&&$F[1],/date/&&$/' data.txt

the data file contains:

name: url1.domain1.com date: 2004/2/1 unwanted info: blah blah blah name: url2.domain5.org date: 2004/3/2 unwanted info: blah blah blah name: url3.domain1.com date: 2004/2/3 unwanted info: blah blah blah name: url4.domain5.org date: 2004/3/4 unwanted info: blah blah blah name: url5.domain1.com date: 2004/2/5 unwanted info: blah blah blah name: url6.domain5.org date: 2004/3/6 unwanted info: blah blah blah

and here are the results of running the script:

1 url1.domain1.com 2004/2/1 2 url2.domain5.org 2004/3/2 3 url3.domain1.com 2004/2/3 4 url4.domain5.org 2004/3/4 5 url5.domain1.com 2004/2/5 6 url6.domain5.org 2004/3/6

Change all the ' into " to run on win32

HTH.

--
hiseldl
What time is it? It's Camel Time!