Fetch a value of particular parameter from a log


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Fetch a value of particular parameter from a log
# 1  
Old 09-16-2010
Fetch a value of particular parameter from a log

Fetch a value of particular parameter from a log.

for exapmle, i have the below line in the log.

Quote:
[2010:09:16 09:01:55] INFO (Employee Details) Name: prabhu, number:12345, location:india, message:timesout while inseting.
[2010:09:16 09:01:55] INFO (Employee Details) Name: aps, number:67890, location:england, message:timesout while inseting.
now i would like to grep name and fetch only the values of name . here in this case i would like to take out only aps and prabhu.


someone please help me on this.
# 2  
Old 09-16-2010
Code:
# awk -F[,\ ] '{print $7}' LOGFILE
prabhu
aps

# 3  
Old 09-16-2010
Code:
sed 's/^.*Name: \([^,]*\),.*$/\1/' your_file
# or
perl -lne '/.*Name:\s*(\w+),/ and print $1' your_file

tyler_durden
# 4  
Old 09-16-2010
Quote:
Originally Posted by durden_tyler
Code:
sed 's/^.*Name: \([^,]*\),.*$/\1/' your_file

In this case, ^ and $ in sed is useless.

Code:
sed 's/.*Name: \([^,]*\),.*/\1/' infile

# 5  
Old 09-16-2010
Or one could even do:
Code:
sed 's/.*Name: //;s/,.*//' infile

or
Code:
awk -F '[ ,]*' '$0=$7' infile

# 6  
Old 09-16-2010
Code:
ruby -ne 'puts $1 if /Name: (.*?),/' file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Call Script with Parameter (that has another parameter)

Hi. How do I achieve this sh /EDWH-DMT02/script/MISC/exec_sql.sh "@/EDWH-DMT02/script/others/CSM_CKC/Complete_List.sql ${file_name}" Complete_List.txt The /EDWH-DMT02/script/MISC/exec_sql.sh has two parameters and it's working fine with this sh /EDWH-DMT02/script/MISC/exec_sql.sh... (7 Replies)
Discussion started by: aimy
7 Replies

2. Shell Programming and Scripting

Resolving a parameter which is passed as parameter

Hi, I have the following files. ->cat scr.sh export TMP_DIR=/home/user/folder1 export TMP_DIR_2=/home/user/folder2 while read line do cat "$line" done<file_list.dat ------------------------ -> cat file_list.dat $TMP_DIR/file1.txt $TMP_DIR_2/file2.txt --------------------------- -> cat... (6 Replies)
Discussion started by: barath
6 Replies

3. Shell Programming and Scripting

How to get the parameter value from the parameter file in perl?

hi all, i have a parameter file of following format, i want a method which can get the value of specific parameter. parameter file format: <Parameter Name="FileLocationWindows"> <Description> The directory location of the logger file. ... (1 Reply)
Discussion started by: laxmikant.hcl
1 Replies

4. Shell Programming and Scripting

Passing parameter to script, and split the parameter

i am passing input parameter 'one_two' to the script , the script output should display the result as below one_1two one_2two one_3two if then echo " Usage : <$0> <DATABASE> " exit 0 else for DB in 1 2 3 do DBname=`$DATABASE | awk -F "_" '{print $1_${DB}_$2}` done fi (5 Replies)
Discussion started by: only4satish
5 Replies

5. Shell Programming and Scripting

Fetch the value from Here Document

I have code like var="1" echo << EOF export `var="2"` EOF echo $var The value of var is printed here is 1 but it should be 2 Any error there? ---------- Post updated at 11:44 AM ---------- Previous update was at 10:33 AM ---------- Also tried var="1" echo var << EOF echo... (1 Reply)
Discussion started by: adisky123
1 Replies

6. Shell Programming and Scripting

make the name of file and fetch few things from log file

Hello All, I am working on a script where I need to fetch the value from a log file and log file creates with different name but few thing are common DEV_INFOMGT161_MULTI_PTC_BLD01.Stage_All_to_stp2perf1.042312114644.log STP_12_02_01_00_RC01.Stage_stp-domain_to_stp2perf2.042312041739.log ... (2 Replies)
Discussion started by: anuragpgtgerman
2 Replies

7. Shell Programming and Scripting

Command that takes one parameter and then searches for the passed in parameter

Hi I am looking for a unix command or a small shell script which can takes one parameter and then searches for the passed in the parameter in any or all files under say /home/dev/ Can anyone please help me on this? (3 Replies)
Discussion started by: pankaj80
3 Replies

8. Shell Programming and Scripting

Fetch PID

Hi All, i get this output when i do PS UX tdntp 9263 0.0 0.0 98464 3200 pts/1 S+ 14:16 0:00 vim FAB1_600015_CONRAD.A0_7XYZ12345.000_LT-SWET.01_LTPA25L_ I want to get the PID of certain specefic filename. so i tried ps ux | pgrep... (13 Replies)
Discussion started by: asheshrocky
13 Replies

9. Ubuntu

Is it possible to fetch my local email log to thunderbird

Hi, I wonder if it possible to read my local user mail log or root mail log in my ubuntu laptop using thunderbird mail client. Im using my the TB mail client for may email management and wonder if it possible to add it to my mail account in TB. You can read your mail log via command mail or... (1 Reply)
Discussion started by: jao_madn
1 Replies

10. Shell Programming and Scripting

how do I make dynamic parameter names? Or get the value of a parameter evaluated twi

Say I write something like the following: var1=1 var2=2 for int in 1 2 do echo "\$var$int" done I want the output to be: 1 2 Instead I get something like: $var1 $var2 (2 Replies)
Discussion started by: Awanka
2 Replies
Login or Register to Ask a Question