Reputation: 367
Input File
ABC
DEF
Output File
ABC
DEF
GHI
I am using
sed -i -e '$a\\GHI ' input.txt
but it adds GHI but not 2 preceding new lines
ABC
DEF
GHI
Upvotes: 2
Views: 1080
Reputation: 58410
This might work for you (GNU sed):
sed '$!b;G;G;aGHI' file
Append a couple of newlines to the pattern space, then append GHI
to the output stream.
N.B. The pattern space is printed before the output stream.
or explicitly:
sed '$G;$G;$aGHI' file
Upvotes: 0
Reputation: 351
use \n to change line for example,a file 1.txt
11111
222222
sed -i '$s/$/\n\n\n333333\n4444444444/' 1.txt
explain:first '$' means last line of file,second '$' means end of line.
result:
11111
222222
333333
4444444444
Upvotes: 0
Reputation: 23667
Since you've tagged linux
, am assuming you have GNU sed and that \n
is recognized
$ cat ip.txt
ABC
DEF
$ sed '$a\\n\nGHI' ip.txt
ABC
DEF
GHI
Add -i
option once it is working
GNU sed doesn't require \
to be used after a
command but has its own use cases. Hence the \\n
at start in previous example. See GNU sed manual for details
$ echo 'foo' | sed '$a123'
foo
123
$ echo 'foo' | sed '$a 123'
foo
123
$ echo 'foo' | sed '$a\ 123'
foo
123
Also, this can be done easily without needing sed
$ printf '\n\nGHI\n' >> ip.txt
$ cat ip.txt
ABC
DEF
GHI
Upvotes: 3