0

I am using the following command to find .js file names from an HTML.

jsFiles=$(echo "$BODY" | sed -rn 's/<script\s.*src=\W(.*.js).*/\1/p')

Sample input:

 <script src="a.js"></script> 
 <script src="b.js"></script> 
 <script src="c.js"></script> 
 <script src="d.js"></script> 

Sample output:

a.js
b.js
c.js
d.js

Now, I want to replace the found file names in HTML.

Sample output:

 <script src="http://10.122.96.13./a.js"></script> 
 <script src="http://10.122.96.13./b.js"></script> 
 <script src="http://10.122.96.13./c.js"></script> 
 <script src="http://10.122.96.13./d.js"></script> 

I have tried the following but didn't work..

for fn in $jsFiles; do
 BODY=$(echo "$BODY" | sed  's/'$fn'/http://10.122.96.13/'$fn'/g')      
done
unh
  • 61
  • 5
  • don't use sed to parse html: https://stackoverflow.com/a/1732454/3784644. Read https://mywiki.wooledge.org/BashFAQ/113 for how to do it properly. – DTSCode Aug 16 '18 at 15:36

1 Answers1

1

Could you please try following.

sed 's#[a-zA-Z]\.js#http://10.122.96.13./&#'  Input_file
RavinderSingh13
  • 130,504
  • 14
  • 57
  • 93