Extracting value from a file updating the same in another file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Extracting value from a file updating the same in another file
# 1  
Old 01-20-2009
Lightbulb Extracting value from a file updating the same in another file

Hi,

I have two different files like this

First File (information file)
# agent.properties
xpm.Location=30000
# logger.properties
xpm.logger.LogLevel=INFO
xpm.logger.NumberOfFiles=5
xpm.logger.MaxFileSize=1MB
# logger.properties
logger.LogLevel=INFO
logger.max_backup_index=5
logger.MaxFileSize=1MB

second file (file name is logger.properties)

xpm.logger.LogLevel=
xpm.logger.NumberOfFiles=5
xpm.logger.MaxFileSize=


Now the question is how can I read the first file to get the value of INFO
from xpm.logger.LogLevel=INFO and update that value in second file where xpm.logger.LogLevel= is present.

Could anyone help me with this..!

Thanks in advance

RaghuDeep AmilineniSmilie

raghu.amilineni
# 2  
Old 01-21-2009
Code:
nawk '{
if (NR==FNR){
	if ($0 ~ /\=/){
		split($0,arr,"=")
		_[arr[1]]=arr[2]
	}
}
else{
	split($0,brr,"=")
	print brr[1]"="_[brr[1]]
}
}' info.txt logger.properties

# 3  
Old 01-21-2009
Code:
INFO=`grep "^xpm.logger.LogLevel=" informationfile | cut -d= -f1`
sed "s/xpm.logger.LogLevel=/&$INFO/g" logger.properties > logger.properties.tmp; mv logger.properties.tmp logger.properties

# 4  
Old 01-21-2009
Thank you very much angheloko ,
it worked fine.and still has some problem.

i executed your code just by changing f1 to f2

#!/bin/sh
INFO=`grep "^xpm.logger.LogLevel=" informationfile | cut -d= -f2`
sed "s/xpm.logger.LogLevel=/&$INFO/g" logger.properties > logger.properties.tmp;
mv logger.properties.tmp logger.properties

but now output is perfect for the first time..and lokks like what i need

this is my information file

# agent.properties
xpm.Location=30000
# logger.properties
xpm.logger.LogLevel=INF2O
xpm.logger.NumberOfFiles=5
xpm.logger.MaxFileSize=1MB
# logger.properties
logger.LogLevel=INFO
logger.max_backup_index=5
logger.MaxFileSize=1MB

this is my logger.properties

xpm.logger.LogLevel=INF2O
xpm.logger.NumberOfFiles=5
xpm.logger.MaxFileSize=

But now , next time if i am exexuting the same script then
i get out put like this

xpm.logger.LogLevel=INF2OINF2O
xpm.logger.NumberOfFiles=5
xpm.logger.MaxFileSize=

it is appending to the existing value...but i should have the same output as the first one..

thanks for ur help..

Last edited by raghu.amilineni; 01-21-2009 at 05:00 AM..
raghu.amilineni
# 5  
Old 01-21-2009
hi summer_cherry,

thank you very much.

your code worked perfectly...

it is showing the out put to console but it is not updating in logger.properties.

could you pls tell me how could this be possible..thank you
raghu.amilineni
# 6  
Old 01-21-2009
Quote:
Originally Posted by raghu.amilineni
But now , next time if i am exexuting the same script then
i get out put like this

xpm.logger.LogLevel=INF2OINF2O
xpm.logger.NumberOfFiles=5
xpm.logger.MaxFileSize=

it is appending to the existing value...but i should have the same output as the first one..

thanks for ur help..
Hahaha! My bad man! Smilie


Code:
INFO=`grep "^xpm.logger.LogLevel=" informationfile | cut -d= -f2`
sed "s/xpm.logger.LogLevel=.*/xpm.logger.LogLevel=$INFO/g" logger.properties > logger.properties.tmp;
mv logger.properties.tmp logger.properties

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Updating in file

hi, i have an csv(which is a month's log file containing userid and log in date ) file which has to be appended to another file say master.log.I need to compare the next month's log data to master.log file .In case, there is new log date for userid it has to get updated in master.log file or i... (2 Replies)
Discussion started by: preema
2 Replies

2. UNIX for Dummies Questions & Answers

Updating a File

Hi, I have a below requirement and need your help in this regard. I have two timestamps in a file i.e. TimeBefore=2014-07-10.18.06.55 TimeAfter_1=2014-07-09.05.45.12 TimeAfter_2=2014-07-09.05.40.12 When I first run the script file, it sets the 'TimeBefore' to todays date. When I run... (5 Replies)
Discussion started by: vrupatel
5 Replies

3. Shell Programming and Scripting

Help updating a file

I can not seem to figure out how to update the attached match.txt column 2 using update.txt. However, only the text before the period in updat.txt appears in match.txt. For example, in update.txt NM_001613.2 matches NM_001613 in match.txt, so is it possible to update the record in match.txt to... (8 Replies)
Discussion started by: cmccabe
8 Replies

4. Shell Programming and Scripting

Reading from one file and updating other file with constant entries

Hi All, Thaks for the help in my last thread. I have one more question. I have two files with ldap entries in it. One file contains all the user LDAP parameter entries (26 MB) and other file contains only the user id's that have to be inactivated. Unix script has to read from the file that has... (8 Replies)
Discussion started by: Samingla
8 Replies

5. Shell Programming and Scripting

Help with reading file with values and updating another file

Hi I need some help with a task, i am an absolute newbie to any form of shell scripting and request guidance. Task: 1. Read a config file in form of name value pair ex host=www.test.com port=8080 binding="dynamic" or "other" or "something else" key1=value1 key2=value2 key3=value4... (4 Replies)
Discussion started by: mk7074
4 Replies

6. UNIX for Dummies Questions & Answers

Updating a field in a File without creating temp file's

Hi Experts, I have a requirement where i need to update the below items in file, 1. END TIME 2. PREV_STATUS For the first time the PREV_status and end time of all job the job will be sysdate & NULL reply as below, Session_name,Load Type,Frequency,Seesion End time,Prev_Status... (2 Replies)
Discussion started by: prabhutkl
2 Replies

7. Shell Programming and Scripting

Parsing file, yaml file? Extracting specific sections

Here is a data file, which I believe is in YAML. I am trying to retrieve just the 'addon_domains" section, which doesnt seem to be as easy as I had originally thought. Any help on this would be greatly appreciated!! I have been trying to do this in awk and mostly bash scripting instead of perl... (3 Replies)
Discussion started by: Rhije
3 Replies

8. Shell Programming and Scripting

awk updating one file with another, comparing, updating

Hello, I read and search through this wonderful forum and tried different approaches but it seems I lack some knowledge and neurones ^^ Here is what I'm trying to achieve : file1: test filea 3495; test fileb 4578; test filec 7689; test filey 9978; test filez 12300; file2: test filea... (11 Replies)
Discussion started by: mecano
11 Replies

9. Shell Programming and Scripting

TO know whether file is updating or not

Hi All, I am new to scripting. my requirement is , I want to know whether the file(i.e., log file) is updating or not. It should search for every 15 min. If it is not updating means it needs to send out a automatic mail. can you please help me in this. (2 Replies)
Discussion started by: raj333
2 Replies

10. Shell Programming and Scripting

Extracting data from text file based on configuration set in config file

Hi , a:) i have configuration file with pattren <Range start no>,<Range end no>,<type of records to be extracted from the data file>,<name of the file to store output> eg: myfile.confg 9899000000,9899999999,DATA,b.dat 9899000000,9899999999,SMS,a.dat b:) Stucture of my data file is... (3 Replies)
Discussion started by: suparnbector
3 Replies
Login or Register to Ask a Question