The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
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

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-24-2008
Registered User
 

Join Date: Feb 2008
Posts: 2
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!
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 03-24-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,111
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
Also, I took the liberty to escape the dots, just to be completely correct.
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 10:06 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0