05-08-2009
Awk help needed for display particular field alone for searching pattern
Hi,
I have a requirement for taking an particular number in a log file. if i grep for the particular string it will retrieve the entire line for the particular string. but i want to display only the string from each line which i am searching for,
Note: The searching field varies its position line to line.
Example:
searching for the field "customerReferenceNumber:" in a trace.log file
grep 'customerReferenceNumber:' trace.log | awk '{print $(NF-1), NF}' | head -10
customerReferenceNumber:14083724 26
customerReferenceNumber:14078919 22
citizenship: 37
customerReferenceNumber:14077854 24
customerReferenceNumber:14073551 26
customerReferenceNumber:14072203 24
customerReferenceNumber:14069692 23
customerReferenceNumber:14066961 25
customerReferenceNumber:14066244 24
customerReferenceNumber:14066212 24
Could you please help me on this.
thanks
Senthil.
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
I got a sample file like this.
$ cat test
12|13|100|s
12|13|100|s
100|13|100|s
12|13|100|s
I want to replace all 100 by 2000 only in 3rd field using "awk"
This is replacing all 100's :-(
$ awk -F "|" '{gsub( /100/,"2000");print}' test
12|13|2000|s
12|13|2000|s
2000|13|2000|s... (5 Replies)
Discussion started by: jkl_jkl
5 Replies
2. Shell Programming and Scripting
hi,
let's say $numbers = "324 350 587" an so on...
what i'm trying to do is this:
awk -v numbers="$numbers" '{if (numbers ~ /$2/) print $0, "bla bla"}' file
# file looks like this:
214 .....
215 ...
216 ....
250
...
324
325
...
350 something ...
...
587 ... (4 Replies)
Discussion started by: someone123
4 Replies
3. Shell Programming and Scripting
using awk convert 3 rd fileld of file as 5 digit and then display changed file.
like
1 2
23445 3452 3343
3 5 6 6
================
o/p:-
1 2
23445 3452 03343
3 5 00006 6 (1 Reply)
Discussion started by: RahulJoshi
1 Replies
4. Shell Programming and Scripting
First, thanks for the help in previous posts... couldn't have gotten where I am now without it!
So here is what I have, I use AWK to match $1 and $2 as 1 string in file1 to $1 and $2 as 1 string in file2. Now I'm wondering if I can extend this AWK command to incorporate the following:
If $1... (4 Replies)
Discussion started by: right_coaster
4 Replies
5. Shell Programming and Scripting
Hi ,
I have the file where i have to search for the pattern. The pattern may be lower case or upper case or camel case. Basically I want to ignore while searching the pattern in awk.
awk '/error|warning/exception/' filename
Please help me (3 Replies)
Discussion started by: arukuku
3 Replies
6. Shell Programming and Scripting
awk 'BEGIN{IGNORECASE=1} /error|warning|exception/ { ++x } END { print x }' filename
The above command returning the number of times the pattern present in the file. But I want the the line number as well. please help me out (6 Replies)
Discussion started by: arukuku
6 Replies
7. UNIX for Dummies Questions & Answers
Hi !
I have a tab-delimited file, file.tab:
Column1 Column2 Column3
aaaaaaaaaa bbtomatoesbbbbbb cccccccccc
ddddddddd eeeeappleseeeeeeeee ffffffffffffff
ggggggggg hhhhhhtomatoeshhh iiiiiiiiiiiiiiii
... (18 Replies)
Discussion started by: lucasvs
18 Replies
8. Shell Programming and Scripting
Hi All,
i have an output of command vmstat as below :
$ vmstat
System configuration: lcpu=4 mem=5376MB ent=1.00
kthr memory page faults cpu
----- ----------- ------------------------ ------------ -----------------------
r b avm fre re pi... (10 Replies)
Discussion started by: omkar.jadhav
10 Replies
9. Shell Programming and Scripting
In the awk I am trying to add :p.=? to the end of each $9 that matches the pattern NM_. The below executes andis close but I can not seem to figure out why the :p.=? repeats in the split as in the green in the current output. I have added comments as well. Thank you :).
file
... (4 Replies)
Discussion started by: cmccabe
4 Replies
10. Shell Programming and Scripting
Hi
I am using awk to print 10,11 column but it is not displaying required output.
Please let me know how I can browse through the line and extract the required one
Example: I have below 2 lines in file
seq 49960| Thu Apr 19 10:57:40.726182 2018|Len: 89|GAP for CL/U18 9P-NC (CL90U8)) gap... (10 Replies)
Discussion started by: sdosanjh
10 Replies
LEARN ABOUT LINUX
dbilogstrip
DBILOGSTRIP(1p) User Contributed Perl Documentation DBILOGSTRIP(1p)
NAME
dbilogstrip - filter to normalize DBI trace logs for diff'ing
SYNOPSIS
Read DBI trace file "dbitrace.log" and write out a stripped version to "dbitrace_stripped.log"
dbilogstrip dbitrace.log > dbitrace_stripped.log
Run "yourscript.pl" twice, each with different sets of arguments, with DBI_TRACE enabled. Filter the output and trace through "dbilogstrip"
into a separate file for each run. Then compare using diff. (This example assumes you're using a standard shell.)
DBI_TRACE=2 perl yourscript.pl ...args1... 2>&1 | dbilogstrip > dbitrace1.log
DBI_TRACE=2 perl yourscript.pl ...args2... 2>&1 | dbilogstrip > dbitrace2.log
diff -u dbitrace1.log dbitrace2.log
DESCRIPTION
Replaces any hex addresses, e.g, 0x128f72ce with "0xN".
Replaces any references to process id or thread id, like "pid#6254" with "pidN".
So a DBI trace line like this:
-> STORE for DBD::DBM::st (DBI::st=HASH(0x19162a0)~0x191f9c8 'f_params' ARRAY(0x1922018)) thr#1800400
will look like this:
-> STORE for DBD::DBM::st (DBI::st=HASH(0xN)~0xN 'f_params' ARRAY(0xN)) thrN
perl v5.12.3 2011-05-06 DBILOGSTRIP(1p)