![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Rules & FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| help required for replacing text in vi | Chandu2u | Shell Programming and Scripting | 6 | 01-26-2008 07:12 AM |
| extracting a set of strings from a text file | Deanne | Shell Programming and Scripting | 2 | 09-20-2007 08:31 PM |
| Replacing text | chrchcol | Shell Programming and Scripting | 3 | 07-25-2006 09:30 AM |
| replacing text | ajaya | Shell Programming and Scripting | 2 | 04-12-2006 09:31 AM |
| Newbie: replacing strings containing special caracters | drumkid | UNIX for Dummies Questions & Answers | 1 | 04-03-2006 11:39 AM |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
replacing strings with text from other file
Hi,
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' Help please! |
| Forum Sponsor | ||
|
|
|
|||
|
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. Code:
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 |
|||
| Google UNIX.COM |