in reply to copying lines in a text file to a new file with a dynamically generated text name
If your files aren't too big, you can slurp the file into a single string. Then you can get the info you need with a simple regex that employs a 'g' flag to get all the matches:
my $text; { local $/ = undef; $text = <DATA>; #"slurp" the whole file } while ($text =~ / (\d+) \. pace (.*?) \d+ \. slow /xmsg ) { print "filename=$1 and text=$2"; } __DATA__ 12345.pace text1 12345.slow 123456.pace text2 123456.slow hyds.pace bla bla bla uiw.slow --output:-- filename=12345 and text= text1 filename=123456 and text= text2
I'll leave the file creation and the writing of the file for you.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: copying lines in a text file to a new file with a dynamically generated text name
by Anonymous Monk on Feb 18, 2011 at 05:04 UTC | |
|
Re^2: copying lines in a text file to a new file with a dynamically generated text name
by seek_m (Initiate) on Feb 18, 2011 at 05:05 UTC |