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.

1 Answer 1

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

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.