regex - Using bash regexp to insert the contents of a file into another -


i have javascript file jquery function call:

$.getscript('/scripts/files/file.js'); 

i want replace line contents of file @ path. bash script have far:

cat public/scripts/old.js | sed -e "s/$\.getscript\('(.)+'\);/$(cat \1)/g"  > public/scripts/new.js 

however, regular expression , remembering path not seem working correctly. cat: 1: no such file or directory seems if cat being called on number 1 (which should remembered portion of regexp). how can fix this?

because using $() inside double quotes, shell parsing cat \1, stripping backslash , trying run cat 1 pass output part of argument sed. sed has command (r) reading file, filename must literal, , cannot result of previous sed commands (at least in standard sed, perhaps implementations provide ability). sed wrong tool this. awk solution, fragile.

here's possible perl solution (warning: fragile):

perl -ne 'if( $_ =~ /\$\.getscript\('"'(.*)'"'\)/ )     { system( "cat $1" ) } else {print}' public/scripts/old.js 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -