Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 445
Zaza Avatar asked Mar 09 '26 00:03

Zaza


1 Answers

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

like image 91
heemayl Avatar answered Mar 11 '26 16:03

heemayl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!