Two of many ways to get the spaces, the first does the newline after the TITLE line, too.
orprint map { chomp; $_ . /^TITLE/? "\n" : ' '; } grep { /$re/ } <FILE>;
The trinary (?:) operator in the first chooses space or newline depending on the first word.{ local $" = ' '; # just making sure - this is the default print "@{[grep {/$re/} <FILE>]}"; }
After Compline,
Zaxo
In reply to Re: print spaces with grep
by Zaxo
in thread print spaces with grep
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |