Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

2 Answers 2

echo '1
2
4' > test.txt
sed -i '' '/^2$/a\
3
' test.txt

(Edited to add -i '')

share|improve this answer

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.