Sed adds content below a line

the requirement is to add new content below a line

CentOS

related codes

sed-I"Nbat / Target text 1Universe a\ / / ancymocknreturn add new content 1" file_path

sed-I"Nbat / Target text 2Universe a\ / / ancymocknreturn add new content 2 "file_path

expected results

Target text 1
/ / ancymock
return new content 1

Target text 2
/ / ancymock
return new content 2

actual results

Target text 1
/ / ancymock
return new content 1

Target text 2
(with a blank line)
/ / ancymock
return new content 2

when the same sed logic is appended to the second target document, a jump line appears. Sometimes I really think rlgl

Sed
Jan.08,2022

$ cat /alidata/abc.txt
abc
My test text

sed -i "$ a\" /alidata/abc.txt

$ cat /alidata/abc.txt
abc
My test text

=

-sharp cat abc.txt
Some text
Random
[option]
insert text here
Some stuff

-sharp sed '/^Some text/{N;s/$/\nadd new line/}' abc.txt
Some text
Random
add new line
[option]
insert text here

add-I to modify the original file.

Menu