David Gilden wrote: > Greetings, Hello,
> I am having a little trouble understanding matching and getting the sub > pattern > saved to a Var. so that I can do a munge. I want to take the line returns and > change them into > pipe characters '|' > All data records start with a date i.e. 01/01/2006 > But there are fields in between that are one multiple lines. Sample data is > below the script. > > Here's what I have so far.... > > #!/usr/bin/perl -w > > > open(FI,"test.txt") || die "Read in, Could not find File, $!"; > my @files = <FI>; > close(FI); > > for (@files){ > > chomp($_); > > $_ =~m|(\d+/\d+/\d+)(?s)(.+?)\d+/\d+/\d+|; > > $2 =~tr/\n/|/; > > print "$1$2\n"; > > # save out modified result... > } > > Given this data: > > 09/01/2006|03:29AM Password for qsocordovam reset by Self Reset utility > Username: qsocordovam > ClientNumber: 77927 > IP address: 24.248.1.241 > 09/01/2006|07:53AM Failed reset attempt > Username: tmpcollic03 > ClientNumber: 110330 > IP address: 152.121.16.7 > Failed challenge question(s) > 09/01/2006|07:55AM Failed reset attempt > Username: tmpcollic03 > ClientNumber: 110330 > IP address: 152.121.16.7 > Failed challenge question(s) > 09/01/2006|08:03AM Failed reset attempt > > Desired result: > 09/01/2006|03:29AM Password for qsocordovam reset by Self Reset > utility|Username: qsocordovam|ClientNumber: 77927|IP address: 24.248.1.241 > #Next record.... starts with a date of format : 09/01/2006 This should do what you want: open FI, 'test.txt' or die "Could not open 'test.txt' $!"; my @lines; while ( <FI> ) { s/\s+\z//; if ( m!^\d\d/\d\d/\d{4}\|! ) { print join( '|', splice @lines ), "\n"; } push @lines, $_; } print join( '|', @lines ), "\n"; close FI; John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>