Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Re: manipulating file contents

by lidden (Curate)
on Sep 29, 2005 at 00:07 UTC ( [id://495949] : note . print w/replies, xml ) Need Help??

in reply to manipulating file contents

Here are two examples that does the same thing. I think the second one is easier to understand for someone new to Perl.
while(<>){ print "$1;\n" if /^(Key [0-5] 0x[\da-f]{14})/i; } while( my $line = <>){ if( my ($match) = $line =~ /^(Key [0-5] 0x[\da-f]{14})/i ){ print "$match;\n"; } }
or maybe you want a one-liner:
perl -ni -le 'print "$1;" if /^(Key [0-5] 0x[\da-f]{14})/i' file.txt
This will change "file.txt".