Skip to main content
11 events
when toggle format what by license comment
Dec 20, 2022 at 10:03 comment added Míng sed '/[^[:space:]]/,$!d', sed -e :a -e '/^[[:space:]]*$/{$d;N;ba' -e '}' and sed -e '/[^[:space:]]/,$!d' -e :a -e '/^[[:space:]]*$/{$d;N;ba' -e '}' can also remove lines with only spaces. (re-comment to fix a bug of the previous one)
Jul 20, 2021 at 13:00 history bounty awarded Gordon
Jul 18, 2021 at 17:29 comment added Gordon In regards to @AndrewHenle's caveat, the command works just as well for streaming, if you don't want to worry about the difference between GNU -i and BSD -i ''
Sep 13, 2020 at 2:58 comment added labyrinth It's better to do something like ^[[:space:]]$ instead of just a newline since there are DOS, Linux, and Mac kinds of newlines that will mess you up if you just try to strip out one kind of them.
Nov 19, 2019 at 5:37 history edited Stack EG CC BY-SA 4.0
added 446 characters in body
Nov 17, 2019 at 10:26 comment added Prvt_Yadav Please explain the individual commands, how they are working and what is the meaning of those flags.
Nov 16, 2019 at 16:41 comment added Joe i see that these commands work, but I'm not quite sure how. Could you explain them in more detail? In particular, in the second example, why doesn't the first clause delete embedded blank lines? Why does the second clause need to loop? It looks like it gets a bunch of newlines at once. Does any of this work on white space-only lines or are you considering them non-blank?
Nov 15, 2019 at 11:27 comment added Andrew Henle Note that -i is a non-portable extension to the POSIX sed utility and will not be available on all systems.
Nov 14, 2019 at 15:35 vote accept Feriman
Nov 14, 2019 at 15:31 history edited Stack EG CC BY-SA 4.0
added 241 characters in body
Nov 14, 2019 at 15:26 history answered Stack EG CC BY-SA 4.0