4 ms·
Here's a trick I wrote with `GNU grep`: grep --group-separator= -A0 '.' The above command is equivalent to the below `awk` command (including removal of e
by asicsp 4y ago
Here's a trick I wrote with `GNU grep`:
grep --group-separator= -A0 '.'
The above command is equivalent to the below `awk` command (including removal of empty lines at start/end of input):
awk -v RS= '{print s $0; s="\n"}'
Both the above solutions can be changed to a different group separator instead of single empty.
You can also just use `cat -s` if you don't need a custom group separator and don't care about start/end empty lines.
$ printf '\n\n\ndragon\n\n\n\n\nunicorn\n\n\n' | cat -s
dragon
unicorn
$ printf '\n\n\ndragon\n\n\n\n\nunicorn\n\n\n' | awk -v RS= '{print s $0; s="\n"}'
dragon
unicorn