awk script and parsing


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk script and parsing
# 1  
Old 08-21-2013
awk script and parsing

Hello

I am trying to find how to do the following with awk and other tools.

Find a line in the file where the element 1 is equal to 12345, from the first occurrence, in that line find the element 11 what is equal to and print all lines in file where their element 11 is equal to the value of that line.

Code:
1=12344 2=2222 3=110 4=111 11=2222
1=12345 2=2222 3=110 4=111 11=55
1=125 2=2222 3=110 4=111 11=55
1=12345 2=2222 3=110 4=111 11=54
1=125 2=2222 3=110 4=111 11=55
1=12345 2=2222 3=110 4=111 11=50

So with this input it will find the value of 11 of line 2 (which is 55 because that line's element 1 is 12345) and it will print all lines with element 11=55

Thanks
Moderator's Comments:
Mod Comment
Please use code tags when posting data and code samples!

Last edited by vgersh99; 08-21-2013 at 04:02 PM..
# 2  
Old 08-21-2013
Try also
Code:
awk '$1=="1=12345" {if (!L) L=$NF} L==$NF' file
1=12345 2=2222 3=110 4=111 11=55
1=125 2=2222 3=110 4=111 11=55
1=125 2=2222 3=110 4=111 11=55

# 3  
Old 08-22-2013
Thanks!!!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

DB2 in awk or PARSING VALUE in Shell Script

Guys, My Motive is, There are some View names in the file with the format of SCHEMA.VIEWNAMe, I want to read the data from file and parse it to SCHEMA and VIEWNAME and execute DB2 command to get the base Table name. I can parse easily through AWK but i could not execute db2 commands in... (1 Reply)
Discussion started by: Nandy
1 Replies

2. Shell Programming and Scripting

Issue with awk script parsing log file

Hello All, I am trying to parse a log file and i got this code from one of the good forum colleagues, However i realised later there is a problem with this awk script, being naive to awk world wanted to see if you guys can help me out. AWK script: awk '$1 ~ "^WRITER_" {p=1;next}... (18 Replies)
Discussion started by: Ariean
18 Replies

3. Shell Programming and Scripting

Another parsing question (awk)

Input File Name of the session: filesrv_quo snap Logical Units UID: 60:06:01:60:01:7B:25:00:C8:86:B0:CA:5B:A2:E0:11 Name of the session: verspn2_at_176_0218 snap Logical Units UID: Name of the session: DRT-ny-iadsql1-c_ny-iadsql2-c snap Logical Units UID: ... (4 Replies)
Discussion started by: greycells
4 Replies

4. Shell Programming and Scripting

Parsing help ( awk)

Input File ( this is a sample record ) Storage Group Name: DRT_ny-iadsql1-c_ny-iadsql2-c Storage Group UID: 00:21:E9:C7:2D:E0:E1:11:82:CC:00:60:16:10:04:0A HBA/SP Pairs: HBA UID SP Name SPPort ------- ... (2 Replies)
Discussion started by: greycells
2 Replies

5. Shell Programming and Scripting

XML Parsing using awk

Hi All, I have a problem to resolve. For following XML file, I need to parse the values based on Tag Name. I would prefer to use this by awk. I have used sed command to replace the tags (s/<SeqNo>//). In this case there can be new tags introduced. So need to parse it based on Tag Name. Any... (9 Replies)
Discussion started by: Tons
9 Replies

6. Shell Programming and Scripting

Shell script not parsing complete file using AWK

Hi, I have shell script which will read single edi document and break data between ST & SE to separate files.Below example should create 3 separate files. I have written script with the below command and it is working fine for smaller files. awk -F\| -vt=`date +%m%d%y%H%M%S%s` \ ... (2 Replies)
Discussion started by: prasadm
2 Replies

7. Shell Programming and Scripting

Parsing through Awk

Hi All, I have an input file something like this: Line1 Line2 .... LineN Identifier ( Field1a, Field1b; Field2a, Field1b; Field3a, Field1b; ..... ) LineN+1 LineN+2 etc.. I basically need Field1a, Field2a, Field3a.... from the above file (6 Replies)
Discussion started by: tostay2003
6 Replies

8. Shell Programming and Scripting

help parsing txt with awk

Hi all I would need some help to introduce 'break' lines into the following data by using awk: original data: RECORD 1000 aaa xxxxxx RECORD 1001 aaa xxxxxx RECORD 1002 bbb xxxxxx RECORD 1003 bbb xxxxxx RECORD 1004 bbb xxxxxx RECORD 1005 ccc xxxxxx RECORD 1006 ccc xxxxxx RECORD 1007... (5 Replies)
Discussion started by: yomaya
5 Replies

9. UNIX for Dummies Questions & Answers

parsing with awk

I have a file that reads like this: name:john name:bill name:james phone:123 phone:456 phone:789 i would like change the file so it appears like this: name:john phone:123 name:bill phone:456 name:james phone:789 any help is greatly appreciated! (1 Reply)
Discussion started by: chknstrp
1 Replies

10. Shell Programming and Scripting

Awk Parsing

Hi there Not to good in awk . So bear with me I would need a one liner to take a file with this in it name: joe smoe; group: group1; name: linda smith; ... (2 Replies)
Discussion started by: bombcan
2 Replies
Login or Register to Ask a Question