Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question

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 
share|improve this answer
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 '12 at 13:58
If you add an empty extension to the -i option, that should work though, fixed in your answer. – slhck Mar 2 '12 at 14:04
echo '1
4' > test.txt
sed -i '' '/^2$/a\
' test.txt

(Edited to add -i '')

share|improve this answer

You must log in to answer this question.

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