replacing strings with text from other file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting replacing strings with text from other file
# 1  
Old 03-24-2008
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!
# 2  
Old 03-24-2008
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Read in search strings from text file, search for string in second text file and output to CSV

Hi guys, I have a text file named file1.txt that is formatted like this: 001 , ID , 20000 002 , Name , Brandon 003 , Phone_Number , 616-234-1999 004 , SSNumber , 234-23-234 005 , Model , Toyota 007 , Engine ,V8 008 , GPS , OFF and I have file2.txt formatted like this: ... (2 Replies)
Discussion started by: An0mander
2 Replies

2. Shell Programming and Scripting

Finding a text in files & replacing it with unique strings

Hallo Everyone. I have to admit I'm shell scripting illiterate . I need to find certain strings in several text files and replace each of the string by unique & corresponding text. I prepared a csv file with 3 columns: <filename>;<old_pattern>;<new_pattern> ... (5 Replies)
Discussion started by: gordom
5 Replies

3. Shell Programming and Scripting

Finding/replacing strings in some files based on a file

Hi, We have a file (e.g. a .csv file, but could be any other format), with 2 columns: the old value and the new value. We need to modify all the files within the current directory (including subdirectories), so find and replace the contents found in the first column within the file, with the... (9 Replies)
Discussion started by: Talkabout
9 Replies

4. Shell Programming and Scripting

Replacing strings in a file from a def file

I am sure that there is something out there but before I learn Perl I thought I would ask. Here is what I need: I need a script or program to substitute string values in an xml file from a pair definition file replace_string -d <file containing string pairs> original_file_in new_file_out The... (3 Replies)
Discussion started by: danields2
3 Replies

5. Shell Programming and Scripting

Extended replacing of nonspecific strings in text files [beware complicated !]

Well, to make another post at this helpful forum :b::D: I recently tried something like this, I want to replace all those numberings/letters that are located between <string>file://localhost/var/mobile/Applications/ and /Documents/</string> numberings =---- replace with: first... (6 Replies)
Discussion started by: pasc
6 Replies

6. Shell Programming and Scripting

Replacing variable Text between fixed strings

Hello all, This is my first post and I hope you can help me out. I searched for quite some hours now and haven't found a simple solution to my problem. It is as following: I got this file: dl.dropbox.com/u/14586156/stuff/Bookmarks.plist and want to replace the Text between... (9 Replies)
Discussion started by: pasc
9 Replies

7. Shell Programming and Scripting

Replacing Strings in a File

I have a input file which looks like this: Value1="" Value2="" Value3="" ListOfValues=" $Value1 $Value2 $Value3" I have another program which computes the values ($val1, $val2, $val3). So if $val1 is 'A', $val2 is 'B' and $val3 is 'C', I should edit the input file so it will look like:... (6 Replies)
Discussion started by: laiko
6 Replies

8. Shell Programming and Scripting

Replacing Strings in a File

I have a input file which looks like this: Value1="" Value2="" Value3="" ListOfValues=" $Value1 $Value2 $Value3" I have another program which computes the values ($val1, $val2, $val3). So if $val1 is 'A', $val2 is 'B' and $val3 is 'C', I should edit the input file so it will look like:... (0 Replies)
Discussion started by: laiko
0 Replies

9. Shell Programming and Scripting

Replacing strings in csv file.

Hi, I have a problem.. 1) I have a file that contains the lines as below : VRF-TM_DummyLab/mse02.lab,mse02.lab,ge-2/0/7.222 VRF-EMS_HUAWEI_MSAN_208/mse01.lab,mse01.lab,xe-1/0/0.208 2) I need a method to read this file, line by line from :... (5 Replies)
Discussion started by: msafwan82
5 Replies

10. Shell Programming and Scripting

Replacing strings in a log file and saves as a new csv

Hello Im new here.I need to replace strings and change it into csv format, or at least saves the file as csv if that would work :p. Heres an example of my scenario 1) I have a log file, named abc.log, and its like a txt based file anyway, and the content looks like this ... (2 Replies)
Discussion started by: tententen
2 Replies
Login or Register to Ask a Question