For one of my problems for class, I have a file where I am to delete duplicate blank lines in a file. so for example, I have an input file that looks like this:
Sample Line 1
Sample line 2
Sample line 3
and the output would then turn all multiple blank lines into a singular one, so the output file would look like this:
Sample Line 1
Sample line 2
Sample line 3
I've been able to complete this with a sed command, but the problem insists that I use awk in order to obtain this output.
The closest I've gotten has been with awk '!x[$0]++'
, but that simply deletes pretty much every blank line. I feel like I'm missing something basic.
Thanks for any help!
$ awk 'NF{c=1} (c++)<3' file
Sample Line 1
Sample line 2
Sample line 3
or if you don't mind an extra blank line at the end:
$ awk -v RS= -v ORS='\n\n' '1' file
Sample Line 1
Sample line 2
Sample line 3
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With