0

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? maybe sed directly? if so how? thank you for reading.

2

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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