Hi
You can insert a line after a line that contains a pattern match.
You need the -i (in-place) modifier for sed.
Code:
<!DOCTYPE html>
<html>
<body>
<h1>What Can JavaScript Do?</h1>
<p id="demo">JavaScript can change HTML content.</p>
</body>
</html>
Code:
sed -i '/<body>/a <food>' test.txt
Code:
matthew-laptop:/home/matthew:2 % sed -i '/<body>/a <food>' test.txt
matthew-laptop:/home/matthew:2 % cat test.txt
<!DOCTYPE html>
<html>
<body>
<food>
<h1>What Can JavaScript Do?</h1>
<p id="demo">JavaScript can change HTML content.</p>
</body>
</html>
matthew-laptop:/home/matthew:2 %
You really need to read a good book or some online tutorials for sed though as the topic is large.
Make sure the book and the tutorials are for GNU sed.
Kind regards
Bookmarks