I know there is a similar question in SO How can I replace mutliple empty lines with a single empty line in bash?. But my question is can this be implemented by just using the sed
command?
Thanks
To answer the question as asked, you'd have to do sed 's/pattern. */&\n/' , otherwise you'll insert the newline right after the match instead of at the end of the line.
You can tell sed to carry out multiple operations by just repeating -e (or -f if your script is in a file). sed -i -e 's/a/b/g' -e 's/b/d/g' file makes both changes in the single file named file , in-place.
Give this a try:
sed '/^$/N;/^\n$/D' inputfile
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