change value of logfile


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers change value of logfile
# 1  
Old 02-21-2011
change value of logfile

Hi,

I have a log file like exyymmdd.log and i need to do is read the log file and inside the logfile if i find the word which starts with PQR002106570.book then i need to replace the value of PQRXXX.book(this is unique) with its corresponding title. A list of id(PQRXXX.book) and its title are in the XLsheet in two columns, so i need to check against thisid of the logfile in the xlsheet and replace the logfile value to title fetching from xlsheet.
logfile sample
011-02-02 13:29:17 172.30.9.192 GET /Gatekeeper.aspx type=wel&id=wel-epub/PQR002106570.book

xlsheet is like

A Child's Garden of Verses. PQR002106570.book
A Christmas Carol. PQR002085154.book

Please help

Waiting for your kind reply
# 2  
Old 02-22-2011
Try...
Code:
$ head xlsheet logfile
==> xlsheet <==
A Child's Garden of Verses. PQR002106570.book
A Christmas Carol. PQR002085154.book

==> logfile <==
011-02-02 13:29:17 172.30.9.192 GET /Gatekeeper.aspx type=wel&id=wel-epub/PQR002106570.book

$ awk 'NR==FNR{x=$NF;$NF="";NF--;a[x]=$0;next}a[$NF]{$NF=a[$NF]}1' xlsheet FS=/ OFS=/ logfile
011-02-02 13:29:17 172.30.9.192 GET /Gatekeeper.aspx type=wel&id=wel-epub/A Child's Garden of Verses.

$

# 3  
Old 02-22-2011
hi,

Thanks for your reply. I tried but not the script is not working,

actually my xlsheet is like this. title in one column and id in one more column
A Child's Garden of Verses. PQR002085329.book A Christmas Carol. PQR002085154.book A Comedy of Marriage and Other Tales. PQR002082772.book
and my log file is like this
2011-02-13 13:13:14 172.30.9.191 GET /Gatekeeper.aspx type=wel&id=wel-epub/PQR002085329.book 80 - 119.234.0.26 MobileRead/1.0+CFNetwork/485.12.7+Darwin/10.4.0 500 0 64 196608 324796
2011-02-13 13:13:14 172.30.9.191 GET /Gatekeeper.aspx type=wel&id=wel-epub/PQR002082772.book 80 - 119.234.0.26 MobileRead/1.0+CFNetwork/485.12.7+Darwin/10.4.0 500 0 64 196608 324796

so now in this case PQR002085329.book should be replaced by A Child's Garden of Verses and PQR002082772 by A Comedy of Marriage and Other Tales.

Please help
# 4  
Old 02-22-2011
Why didn't you post your actual data files format initially?
# 5  
Old 02-22-2011
Hi,

I am sorry if i could not explain correctly at the firstplace. I cut the part of the log and pasted it at first time and now i copied the entire logfile.

xlsheet one even though i copy in the form of two columns the data display is not looking like that

very sorry for the inconvience.
# 6  
Old 02-22-2011
I was just curious why people ask for help for a specific problem then say "actually my data looks like this". You're not the first. I just don't get it.

Anyway, try...
Code:
$ head xlsheet logfile
==> xlsheet <==
A Child's Garden of Verses. PQR002085329.book A Christmas Carol. PQR002085154.book A Comedy of Marriage and Other Tales. PQR002082772.book

==> logfile <==
2011-02-13 13:13:14 172.30.9.191 GET /Gatekeeper.aspx type=wel&id=wel-epub/PQR002085329.book 80 - 119.234.0.26 MobileRead/1.0+CFNetwork/485.12.7+Darwin/10.4.0 500 0 64 196608 324796
2011-02-13 13:13:14 172.30.9.191 GET /Gatekeeper.aspx type=wel&id=wel-epub/PQR002082772.book 80 - 119.234.0.26 MobileRead/1.0+CFNetwork/485.12.7+Darwin/10.4.0 500 0 64 196608 324796

$ awk 'NR==FNR&&NF{x=$NF;$NF="";a[x]=$0;next}a[$3]{$3=a[$3]}NF' RS=.book xlsheet RS='\\n' FS='(/|\\.book)' OFS=/ logfile
2011-02-13 13:13:14 172.30.9.191 GET /Gatekeeper.aspx type=wel&id=wel-epub/A Child's Garden of Verses. / 80 - 119.234.0.26 MobileRead/1.0+CFNetwork/485.12.7+Darwin/10.4.0 500 0 64 196608 324796
2011-02-13 13:13:14 172.30.9.191 GET /Gatekeeper.aspx type=wel&id=wel-epub/A Comedy of Marriage and Other Tales. / 80 - 119.234.0.26 MobileRead/1.0+CFNetwork/485.12.7+Darwin/10.4.0 500 0 64 196608 324796

$

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Logfile monitoring with logfile replacement

Bonjour, I've wrote a script to monitor a logfile in realtime. It is working almost perfeclty except for two things. The script use the following technique : tail -fn0 $logfile | \ while read line ; do ... some stuff done First one, I'd like a way to end the monitoring script if a... (3 Replies)
Discussion started by: Warluck
3 Replies

2. Shell Programming and Scripting

Logs from logfile

Hi Team, Have to write a shell script to pick only 1 hr logs from the generated logfile and send it to other logfile. Thanks & Regards, Indu (3 Replies)
Discussion started by: indira_s
3 Replies

3. Shell Programming and Scripting

Logfile Reading

I am reading through a log file that has multiple entries: xx-xxxx-xxx-130111090001 <XML> ... ... </XML> ... ... ... xx-xxxx-xxx-130111100001 <XML> ... ... </XML> There are 2 parts: 1) Take the XML statement and parse out. I have that with a sed script sed -n '/<XML>/,/XML>/p'... (6 Replies)
Discussion started by: SivaAfi
6 Replies

4. Shell Programming and Scripting

Parsing Logfile

Hi, I need to continuously monitor a logfile to get the log information between a process start and end. the logfile look like this abcdddddddddd cjjckkkkkkkkkkkk abc : Process started aaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbb abc... (6 Replies)
Discussion started by: Byorg
6 Replies

5. UNIX for Dummies Questions & Answers

writing to a logfile

I cannot get anything to go to my log. This is what i see on my screen when i run my korn shell. cd ok, cwd=/export/home/tsp_inst/TSP pget: /nas4/edata/tsp/rawdata/test2.gz: File exists But i cant get it to write it to my log. cd /this/is/my/newdirectory lftp -e 'pget -c -n 4... (1 Reply)
Discussion started by: tyngsboro
1 Replies

6. Shell Programming and Scripting

logfile parsing

I thought I was pretty handy with awk until I got this one. :) I'm trying to parse a log file where the events could have different delimiters (2 scripts is ok), the errors are spread over multiple lines, and I"m trying to figure out how to not read the same lines that have already been read. ... (1 Reply)
Discussion started by: linkslice
1 Replies

7. UNIX for Dummies Questions & Answers

Logfile manipulation

Hi First of all I m a complete newbie to Linux ... just started working on it exactly a week ago. I know a bit of programming in C but not very good in it.:D I was given task in my workplace and need some help nAJLR02F030879 9805 Thu Nov 19 13:27 <customerservice@YYY.com> ... (2 Replies)
Discussion started by: abilash.amara
2 Replies

8. Shell Programming and Scripting

logfile

hi iam new of the ksh script.iwant in formation of how to call in logfile in ksh scripts. if the meaning in ksh. please help me thanks naveen.g (1 Reply)
Discussion started by: naveeng.81
1 Replies

9. Shell Programming and Scripting

last month's logfile

hi friends I need a shell script which will do the following Task Enter the month : if you enter 1 then it ll show you last 1 month's (starting from today).log file in the current directry. if you enter 4 then it ll show you last 4 month's (starting from today).log file in the current... (2 Replies)
Discussion started by: deep_kol
2 Replies

10. Shell Programming and Scripting

sort a logfile

Hi experts, I need help to sort a big logfile. logfile: ------- 67712 dkjd jd jj jjjj ------ kjkj jhjh kkk yggg lll hhh gffgf jj -------- i kkk kllkkl ------- Now I want every think between the "------" in one line. Normaly with paste no problem but you can see that the... (7 Replies)
Discussion started by: joerg
7 Replies
Login or Register to Ask a Question