I have a file named foo
where I want to replace the line containing the following regex match:
<script.*src="(.*)".*><\/script>
With the content of a file which name equals the first capture group in the regex above. For example, I might have the following line in foo
:
<script type="text/javascript" src="bar.js"></script>
Which I want to replace with the content from the file bar.js
.
I want to somehow open the file referenced by the first capture group. This is what I have so far:
sed -r "s/<script.*src=\"(.*)\".*><\/script>/$(cat \1) /" foo
But I am getting cat: 1: No such file or directory
.
Even when I try to manually specify the file I want to open I get an Error which I can't understand:
sed -r "s/<script.*src=\"(.*)\".*><\/script>/$(cat bar.js)/" test.txt
Error:
sed: -e expression #1, char 53: unterminated `s' command