Match configuration files with a script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Match configuration files with a script
# 1  
Old 07-02-2008
Java Match configuration files with a script

Hi all,

Can you help me make a script(ksh-Solaris 8) that will match two configuration files?

I have some problems with sed newline.

The script should at least match the value of parameters from one file to another, which looks always like this:

parameter1=some_value
parameter2=some_value2 etc..


My first try is the piece of code below but sed does not insert a new line using "\n" or the other method which was "\"+enter...

Thanks

Code:
for var1 in `diff /etc/opt/config/db.cfg /etc/opt/config2/db.cfg | grep ^\> | awk -F" " '{ print $2 }'`
do
value=`echo $var1 | awk -F"=" '{ print $2 }'`
param=`echo $var1 | awk -F"=" '{ print $1 }'`

# This is done with the intention of replacing "param=OLD_VALUE with param=NEW_VALUE"
cat /etc/opt/config2/db.cfg | sed s/$param/$param=$value\nTODELETE/1 | grep -v ^TODELETE
#the break is included just for testing one parameter
break
done

# 2  
Old 07-02-2008
Try surrounding your sed script with "quotes".
# 3  
Old 07-02-2008
How to insert values out of two same lines in a file

Sorry

Last edited by madhusmita; 07-02-2008 at 03:57 AM.. Reason: Sorry
# 4  
Old 07-02-2008
It does not work with quotes, it just inserts an "n".

I just found a way around that( inspired from this forum Smilie ).

Seems like with this the old value gets replaced with the new value. Basically it deleted everything from "=" to the end of that line.

value1=vvv
param=ppp
value2=222
echo "$param=$value" | sed -n -e 's/^\([^=]*\)=.*/\1/p' | sed s/$param/$param=$value2/1


Still I'm not sure that my initial loop will be the most effective as there are many parameters to replace in both files and sometimes the parameters repeat.

I can have for example:

[name1]
param1=some_value
...
[name2]
param1=some_other_value
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Data match 2 files based on first 2 columns matching only and join if match

Hi, i have 2 files , the data i need to match is in masterfile and i need to pull out column 3 from master if column 1 and 2 match and output entire row to new file I have tried with join and awk and i keep getting blank outputs or same file is there an easier way than what i am... (4 Replies)
Discussion started by: axis88
4 Replies

2. Shell Programming and Scripting

awk to match field between two files and use conditions on match

I am trying to look for $2 of file1 (skipping the header) in $2 of file2 (skipping the header) and if they match and the value in $10 is > 30 and $11 is > 49, then print the line from file1 to a output file. If no match is foung the line is not printed. Both the input and output are tab-delimited.... (3 Replies)
Discussion started by: cmccabe
3 Replies

3. Shell Programming and Scripting

New files based off match or no match

Trying to match $2 in original_targets with $2 of new_targets . If the two numbers match exactly then a match.txt file is outputted using the information in the new_targets in the beginning 4 fields $1, $2, $3, $4 and value of $4 in the original_targets . If there is "No Match" then a no... (2 Replies)
Discussion started by: cmccabe
2 Replies

4. Shell Programming and Scripting

How to use awk shell script to compare and match two files?

Basically, I have two files dupestest.txt 152,153 192,193,194 215,216 290,291 2279,2280 2282,2283haftest.txt 152,ABBOTS ROAD 153,ABBOTS ROAD 154,ABBOTS ROAD 155,ABBOTS ROAD 156,ABBOTS ROAD 157,ABBOTS ROADI want to find the numbers in dupestest.txt in haftest.txt... (4 Replies)
Discussion started by: amyc92
4 Replies

5. Shell Programming and Scripting

Complex match of numbers between 2 files awk script

Hello to all, I hope some awk guru could help me. I have 2 input files: File1: Is the complete database File2: Contains some numbers which I want to compare File1: "NUMBERKEY","SERVICENAME","PARAMETERNAME","PARAMETERVALUE","ALTERNATENUMBERKEY"... (9 Replies)
Discussion started by: Ophiuchus
9 Replies

6. Shell Programming and Scripting

script to match patterns in 2 different files.

I am new to shell scripting and need some help. I googled, but couldn't find a similar scenario. Basically, I need to rename a datafile. This is the scenario - I have a file, readonly.txt that has 2 columns - file# and name. I have another file,missing_files.txt that has id and name. Both the... (3 Replies)
Discussion started by: mathews
3 Replies

7. Shell Programming and Scripting

Script to Match first field of two Files and print

Hi, I want to get script or command in Sun Unix which matches first fields of both the files and print the feilds of one files, example may make it more clear. InputFile1 ================== Alex,1,fgh Menthos,45454,toto Gothica,855,ee Zenie4,77,gg Salvatore,66,oo Dhin,1234,papapa... (3 Replies)
Discussion started by: indian.ace
3 Replies

8. UNIX for Dummies Questions & Answers

mawk script to compare 2 files and report where they match

I have two files and would like a report of where they match. Example of file1: 1 1 1 2 2 2 13 14 15 4 4 4 15 16 17 100 102 1004 56 57 890 Example of file2: 2 2 2 16 10 11 45 22 35 13 14 15 1001 1002 3456 100 102 1004 (1 Reply)
Discussion started by: kenneth.mcbride
1 Replies

9. Shell Programming and Scripting

A script for converting raid configuration log messages to ChangeLog files. ....

hi to all am new to shell scripting..itz very urgent. when i excuting the command metastat(raid configuration info) it will display some information. #metastat d1:submirror status: okey pass:1 d2:submirror staus:okey d3:submirror staus:error if staus is okey.no problem.once i... (0 Replies)
Discussion started by: arjunreddy3
0 Replies
Login or Register to Ask a Question