Based on your question, the strings to capture is on the lines with "Equipment" and "solved" labels; they may be fixed length, and/or match a particular pattern expressable by a regex. So maybe something like this (not tested):
If you don't get what that's doing, read up on perl regular expressions (man pages "perlretut", "perlre", and numerous other reference works). Basically, the "if" is looking for the line that starts with "Equipment:" and contains a string of digits followed immediately by a dash and a set of non-whitespace characters; these latter two things are retained for later use (as $1 and $2) via the paren operaters. Likewise, the "elsif" is looking for the "solved" line, and capturing the next non-whitespace string from that line, along with anything enclosed in double-quotes.... while (<FILE>) { if ( /^Equipment:.*?(\d+)-(\S+)/ ) { ( $str1, $str2 ) = ( $1, $2 ); } elsif ( /^solved:\s+(\S+)\s+"([^"]+)/ ) { ( $str3, $str4 ) = ( $1, $2 ); print "Found: str1= $str1 str2= $str2 str3= $str3 str4= $str4\ +n"; } }
In reply to Re: How do I extract some records from a textfile
by graff
in thread How do I extract some records from a textfile
by bory
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |