rcwizard12435 rcwizard12435 - 1 month ago 7
Bash Question

How can I modify a blank line with a new line using sed

I would like to insert the word "NO" in all of the blank lines in this file using the sed command

1234
124
12453
12463
13442
3462



421532
124135

12


I am trying this command but I am not sure why it does not work:

sed '/'[:blank:]'/ c\ NO' inputfile.txt > outputfile.text


Would it be easier to not use sed command?

fd0 fd0
Answer Source

Substitute lines that begin and end with a newline with NO, using anchors.

sed 's/^$/NO/' inputfile.txt > outputfile.text