My Perl knowledge is thin but since no one else has provided a Perl answer I'll give it a go.
Pass your data in as file and it will print tab-separated lines with three values per line:
perl -e 'while (<>) { $s .= $_; } chomp $s; @arr = split(/\n{2,}/, $s); foreach my $a(@arr) { $a =~ s/Filename: ([^\n]*)\nType: ([^\n]*)\nSize: ([^\n]*)\n.*/$1\t$2\t$3\n/ || next; print "$a"; } ' infile
Result:
XXXXX XXX XXXX
YYYYY YYY YYYY
It's a bit brute-force beast that splitsbut works by splitting the input up into "paragraphs" or blocksparagraphs/blocks and then then applies your multi-line regex to each. (Each block must be separated by an empty line.) If that regex doesn't match then the block is skipped (i
Details.e. if a value is missing after Filename, Size, or Type).
while (<>) { $s .= $_; }- Slurp the input into a single string.chomp $s- Remove trailing newline from the string.@arr = split(/\n{2,}/, $s)- Split string on consecutive newlines. This breaks it up into paragraphs/blocks. Store the blocks in an array.foreach my $a(@arr)- Loop over each array element (block). The next two lines of code are applied to each block.$a =~ s/Filename: ([^\n]*)\nType: ([^\n]*)\nSize: ([^\n]*)\n.*/$1\t$2\t$3\n/ || next- Extract values from the three fields of interest. If no substitution occurs (meaning the regex doesn't match because, for example, a value is missing) then skip this block and move to the next one.print "$a"- Print the result of the substitution: the three values separated by tabs.
Let me re-emphasize thatAgain, I don't use much Perl so there probably are surely more elegant solutions than this.