sed: delete blank lines and modify line immediately after such
sed 4.2.2 on arch 3.18.0
I have many files containing multiple paragraphs of text. In some there are no blank lines and each paragraph begins with a single TAB character. This is the standard I wish to apply to all other files, so I want to remove all blank lines and prepend their following line with a TAB. I believed the following sed script would do the job Code:
~ $ sed '/\s*/ { Code:
drwxr-xr-x 12 root root 4096 Oct 18 09:36 var/ Code:
drwxr-xr-x 12 root root 4096 Oct 18 09:36 var/ |
/\s*/ means nothing, it is useless, it matches always, if you want to specify empty lines use /^\s*$/ instead
sed is not able to do multi line search/replace, so using \n will not work N will join two lines, that is ok, you just need to replace the empty line with a single tab before that. |
Quote:
Code:
sed 's/^\s*$/\t/' N p |
How about something like:
Code:
sed -e '/^\s*$/{N;s/^\s*\n/\t/}' |
Quote:
|
Not that it is too important, but for future onlookers, the '-e' is not required. In my doodlings I was initially trying multiple sed statements joined together :)
|
All times are GMT -5. The time now is 01:22 AM. |