Im trying to update some properties files with text from another file:
file1
user=xyz
file2
user=
after script
file2
user=xyz
Im using this reading the $QUARTZURL,ETC... from quartz.properties:
echo "1,\$s/org.quartz.dataSource.myDS.URL#./org.quartz.dataSource.myDS.URL=$QUARTZURL/g" > tmp;
echo "1,\$s/org.quartz.dataSource.myDS.user#./org.quartz.dataSource.myDS.user=$QUARTZUSER/g" >> tmp;
echo "1,\$s/org.quartz.dataSource.myDS.password#.*/org.quartz.dataSource.myDS.password=$QUARTZPASSWORD/g" >> tmp;
sed -f tmp quartz.properties >quartz.properties.new
I keep getting:
sed: file tmp line 3: unknown option to `s'
sed: file tmp line 1: unknown option to `s'
sed: file tmp line 1: unknown option to `s'
sed: file tmp line 1: unknown option to `s'
I can't repro that here. Is the file longer than what you are really showing? Or do the variables contain slashes? I guess at least the URLs do! In that case you need to use a different separator, or escape the slashes. Of course, if the password can contain just about anything, you won't know in advance what separator character to use.
As a stylistic comment, you can use a here document instead of a temporary file.
sed -f - quartz.properties <<"HERE" >quartz.properties.new
1,\$s/org\\.quartz\\.dataSource\\.myDS\\.URL#.*/org.quartz.dataSource.myDS.URL=$QUARTZURL/g
1,\$s/org\\.quartz\\.dataSource\\.myDS\\.user#.*/org.quartz.dataSource.myDS.user=$QUARTZUSER/g
1,\$s/org\\.quartz\\.dataSource\\.myDS\\.password#.*/org.quartz.dataSource.myDS.password=$QUARTZPASSWORD/g
HERE
Also, I took the liberty to escape the dots, just to be completely correct.