1

I have an HTML file. One line is the file is white space followed by this text:

<!-- insert new downloads here -->

How can I insert a line of text after that line in the file, just from the command line?

2 Answers 2

2

I did some sed research and this seems to work:

sed -i '' -e 's/<!-- insert new downloads here -->/<!-- insert new downloads here -->\
new content/' input.html 
2
  • That command produces a backup file called input.html-e, which contains the old content, since the -i option takes the backup file extension as an argument.
    – slhck
    Mar 2, 2012 at 13:58
  • If you add an empty extension to the -i option, that should work though, fixed in your answer.
    – slhck
    Mar 2, 2012 at 14:04
0
echo '1
2
4' > test.txt
sed -i '' '/^2$/a\
3
' test.txt

(Edited to add -i '')

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .