Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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 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

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


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.