in reply to Simple perl one-liner for transforming text files
Not quite one line, but...
You're 'records' are separated by a new blank line so set the input record separator ($/) to a pair of newlines. Then split each record on newlines and take the part after the colon for the fields you want.
#!/usr/bin/perl -w use strict; $/ = "\n\n"; while (<DATA>) { my @wanted = map { (split(/:\s+/))[1] } (split /\n/)[0..1]; print "@wanted\n"; } __DATA__ 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
--- print map { my ($m)=1<<hex($_)&11?' ':''; $m.=substr('AHJPacehklnorstu',hex($_),1) } split //,'2fde0abe76c36c914586c';
|
|---|