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 use a bash script to add a javascript file to a directory, but after that I need to insert into the index.html this line at between line 30 and 31.

<script type="text/javascript\" src="./js/jquery.browser.js\"></script>

I used the following command in my but it doesn't work (it prints me the content of the index.html like cat would do) :

sed '30i\ <script type=\"text/javascript\" src=\"./js/jquery.browser.js\"></script> ' /path/to/index.html

should I use perl? if so how? thank you for reading.

share|improve this question

1 Answer 1

You need to add option -i, to make it update the file, not write to standard out.

Also 30i inserts before line 30, so you need 31i. Also you inserted a single space, I assume this is in error.

So you need:

sed -i '31i\<script type=\"text/javascript\" src=\"./js/jquery.browser.js\"></script> ' /path/to/index.html
share|improve this answer

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.