eadmin eadmin eadmin eadmin - 23 days ago 6
Linux Question

creating a blank line after some specific line using bash / linux

I need to add an additional blank line after the line 45 using sed

for example:

44 some text one
45 some text two
46 some text three
47 some text four


result:

44 some text one
45 some text two
46
47 some text three
48 some text four


I've tried to use

sed '45G' myfile.txt


but not seems to be working, it does prints content of the file on the screen but do not adds any space after the line 45

Using CentOS 7 minimal

Answer

You can do:

sed $'45 a \n' file.txt
  • $'' initiates C-style quoting, might be needed in some sed while using \n

  • 45 a \n appends a newline (\n) after (a) the 45-th line

Comments