How to add blank line after every grep result using Perl?
This is the direct answer to your question:
grep 'xyz' | perl -pe 's/$/\n/'
But this is better:
perl -ne 'print "$_\n" if /xyz/'
EDIT
Ok, after your edit, you want (almost) this:
grep 'xyz' * | perl -pe 'print "\n" if /^([^:]+):/ && ! $seen{$1}++'
If you don’t like the blank line at the beginning, make it:
grep 'xyz' * | perl -pe 'print "\n" if /^([^:]+):/ && ! $seen{$1}++ && $. > 1'
NOTE: This won’t work right on filenames with colons in them. :)½
Adding blank line spaces before and after pattern 'string' match
sed -r 's/(^.*)(string)(.*$)/\1\n\n\n\n\n\2\n\n\n\n\n\3/' text.txt
Use -r or -E to allow regular expressions, split likes into three sections and then substitute the line for the first section, 5 new lines, the second section, 5 new lines and then finally the third section.
Add blank line before a certain phrase in a text file in Linux?
Sure, you can use Perl.
perl -pe 's/^Nmap/\nNmap/'
Related Topics
Component Based Web Project Directory Layout with Git and Symlinks
How to Connect to Postgresql Server: Could Not Connect to Server: Permission Denied
How to Return Spawned Process Exit Code in Expect Script
How to Use Kgdb Over Ethernet (Kgdboe)
How to Batch Resize Millions of Images to Fit a Max Width and Height
How to Use the Linux Flock Command to Prevent Another Root Process from Deleting a File
What's the Point of Using Busybox in a Low Ram Embedded System
Sonar - Measure Code Coverage Using Cobertura
Bash - Surround All Array Elements or Arguments with Quotes
Open a File Directly from a Gitlab Private Repository
Find and Remove Files with Space Using Find Command on Linux
Docker Copy with File Globbing
Gdb Break When Program Opens Specific File
How to Reset Emacs to Save Files in Utf-8-Unix Character Encoding