awk to find pattern in file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk to find pattern in file
# 8  
Old 04-20-2018
Code:
awk -v code="${CODE}"  -F'[. ]' '$4!=code{next} $5=="qTime"{qt=$0;next}$5=="qStop" && qt{print qt;qt==""}1' myFile

but RudiC's suggestion is more elegant - not sure if it'd work if there were multiple "blocks" in the same file Smilie
# 9  
Old 04-20-2018
Quote:
Originally Posted by RudiC
Like so:
Code:
grep -F ".BY." file | sort -t. -k2,2r -k4,4 -k5,5
xxxx.Merge.exchMon.BY.qStart         09:55               read
xxxx.Merge.exchMon.BY.qStop          15:30               read
xxxx.Merge.exchMon.BY.qTime          120                 read
xxxx.DelayTracker.BY.tStart       09:55                   read
xxxx.DelayTracker.BY.tStop        15:30                   read


Thanks RudiC
that worked as expected Smilie

Can you please also explain a bit what does this sort means (sort -t. -k2,2r -k4,4 -k5,5)
# 10  
Old 04-20-2018
man pages frequently help.

man sort:
Quote:
-k, --key=KEYDEF
sort via a key; KEYDEF gives location and type
.
.
.
-t, --field-separator=SEP
use SEP instead of non-blank to blank transition
so
-t. use dot as field separator
-k2,2r first sort key: 2. field, reverse sort
-k4,4 next key: fourth field

etc.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed and awk to find pattern and add priffix

Original File Server1|poweredOn|268401| Server1/Server1.vmx|Red Hat Enterprise Linux 5 (64-bit) Need Output Server1|poweredOn|DR|T1|268401| Server1/Server1.vmx|Red Hat Enterprise Linux 5 (64-bit) Conduction to check find the string "SFCHT1" and "SR" and add prefix has... (4 Replies)
Discussion started by: ranjancom2000
4 Replies

2. Shell Programming and Scripting

Using awk or sed to find a pattern that has lines before and after it

Dear gurus, Please help this beginner to write and understand the required script. I am looking for useing awk for sed. I have a few thousand lines file whose contain are mostly as below and I am trying to achieve followings. 1. Find a string, say user1. Then hash the line containing the... (6 Replies)
Discussion started by: ran_bon_78
6 Replies

3. Shell Programming and Scripting

Big pattern file matching within another pattern file in awk or shell

Hi I need to do a patten match between files . I am new to shell scripting and have come up with this so far. It take 50 seconds to process files of 2mb size . I need to tune this code as file size will be around 50mb and need to save time. Main issue is that I need to search the pattern from... (2 Replies)
Discussion started by: nitin_daharwal
2 Replies

4. Shell Programming and Scripting

[awk] find pattern, change next two lines

Hi, hope you can help me... It seems like a straightforward problem, but I haven't had any success so far using my basic scripting and awk "skills": I need to find a pattern /VEL/ in an input file that looks like this: 1110SOL OW25489 1.907 7.816 26.338 -0.4365 0.4100 -0.0736 ... (3 Replies)
Discussion started by: origamisven
3 Replies

5. Shell Programming and Scripting

How to find a file with a specific pattern for current sysdate & upon find email the details?

I need assistance with following requirement, I am new to Unix. I want to do the following task but stuck with file creation date(sysdate) Following is the requirement I need to create a script that will read the abc/xyz/klm folder and look for *.err files for that day’s date and then send an... (4 Replies)
Discussion started by: PreetArul
4 Replies

6. Shell Programming and Scripting

AWK match $1 $2 pattern in file 1 to $1 $2 pattern in file2

Hi, I have 2 files that I have modified to basically match each other, however I want to determine what (if any) line in file 1 does not exist in file 2. I need to match column $1 and $2 as a single string in file1 to $1 and $2 in file2 as these two columns create a match. I'm stuck in an AWK... (9 Replies)
Discussion started by: right_coaster
9 Replies

7. Shell Programming and Scripting

awk to find pattern and add lines

My file goes like this: SID_LIST_HOSTNAME_LISTENER_3 = (SID_LIST = (SID_DESC = (SID_NAME = ORA0008) (ORACLE_HOME = /opt/oracle/product/ORA0008) (ENVS = "LD_LIBRARY_PATH=/opt/oracle/product/ORA0008/lib") ) (SID_DESC = (SID_NAME = ORA0007) ... (4 Replies)
Discussion started by: jpsingh
4 Replies

8. Shell Programming and Scripting

awk command to find particular pattern in file.

Hi I am using the following command to look for anything other than "0000" in a comma seperated file on 11th field. Note: I am looking for "0000" including the double quotes. nawk -F"," '$11!='"0000"'{print $11}' file This is showing incorrect result. Help is appreciated (2 Replies)
Discussion started by: pinnacle
2 Replies

9. UNIX for Advanced & Expert Users

awk script, find pattern

I have a .csv file with columns. In column I like to find which rows contain a certain pattern. That is, my column is: CNR CP CSN CTC EF.DB.U CTC.A D.DB Here, I like to do one thing with EF.DB.U and another with all other. So my question is; how should my if... (3 Replies)
Discussion started by: lulle
3 Replies
Login or Register to Ask a Question