in reply to How do I extract some records from a textfile

Let's suppose that the file data you're using as input are consistent, and always have the form you've shown -- at least, let's assume they consiste of one or more "records" where each record contains multiple lines, and exactly three of these lines that begin with the labels "Equipment:", "solved:" and "Lab:".

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):

... 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"; } }
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.

Replies are listed 'Best First'.
A reply falls below the community's threshold of quality. You may see it by logging in.