Parsing help ( awk)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Parsing help ( awk)
# 1  
Old 08-09-2013
Parsing help ( awk)

Input File ( this is a sample record )

Code:
 
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
  -------                                          -------     ------ 
  20:00:00:00:C9:9E:07:11:10:00:00:00:C9:9E:07:11   SP A         0
  20:00:00:00:C9:9E:07:11:10:00:00:00:C9:9E:07:11   SP B         1
  20:00:00:00:C9:9E:1F:6A:10:00:00:00:C9:9E:1F:6A   SP B         0
  20:00:00:00:C9:9E:1F:6A:10:00:00:00:C9:9E:1F:6A   SP A         1
HLU/ALU Pairs:
  HLU Number     ALU Number
  ----------     ----------
HLU/SLU Pairs:
 HLU No.  SNAP SHOT UID                                     SNAP SHOT NAME
 ------  -----------------------------------------------    --------------
 1       60:06:01:60:32:BB:21:00:B0:AB:B3:FD:33:E0:E1:11      ny-iadsql1_2-cj-2450-0916-31_DRBCV
 2       60:06:01:60:32:BB:21:00:CC:07:E9:04:34:E0:E1:11      ny-iadsql1_2-cj-2450-0916-32_DRBCV
 0       60:06:01:60:32:BB:21:00:0E:DF:3F:17:9F:00:E3:11      ny-iadsql1-cj_nypiadsql2-cj_LUN_1216_R2_DRBCV

Need the output in this format

Code:
 
UID,SNAPSHOTNAME,HLU,STORAGEGROUP
60:06:01:60:32:BB:21:00:B0:AB:B3:FD:33:E0:E1:11,nyp-iadsql1_2-cj-2450-0916-31_DRBCV,1,DRT_ny-iadsql1-c_ny-iadsql2-c
60:06:01:60:32:BB:21:00:CC:07:E9:04:34:E0:E1:11,nyp-iadsql1_2-cj-2450-0916-32_DRBCV,2,DRT_ny-iadsql1-c_ny-iadsql2-c
60:06:01:60:32:BB:21:00:0E:DF:3F:17:9F:00:E3:11,nyp-iadsql1-cj_nypiadsql2-cj_LUN_1216_R2_DRBCV,0,DRT_ny-iadsql1-c_ny-iadsql2-c

The file has number of records like this ....

Thanks
# 2  
Old 08-09-2013
If perl is ok:
Code:
perl -lane 'if (/Name:\s+(\S+)/){$group=$1};if(/^\s*(\d+)\s+(\S+)\s+(\S+)/i && $group){print $2.",".$3.",".$1.",".$group}' infile

This User Gave Thanks to Klashxx For This Post:
# 3  
Old 08-09-2013
I do assume that the p here is a typo?
60:06:01:60:32:BB:21:00:B0:AB:B3:FD:33:E0:E1:11,nyp-iadsql1_2-cj-2450-0916-31_DRBCV,1,DRT_ny-iadsql1-c_ny-iadsql2-c

Using awk
Code:
awk '/Name:/ {n=$4} $0~/^ *[0-9]+ +/ {print $2,$3,$1,n}' OFS=","

This User Gave Thanks to Jotne For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

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... (2 Replies)
Discussion started by: koutroul
2 Replies

2. 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

3. 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

4. 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

5. Shell Programming and Scripting

parsing xml using awk

hello , i am trying to parse xml using awk however its a little bit tricky as i want <databases> <source> <host>prod</host> <port>1522</port> <tns>GP1</tns> <user>P11</user>... (6 Replies)
Discussion started by: amit1_x
6 Replies

6. 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

7. Shell Programming and Scripting

awk and file parsing

Hi, I have a input file like this TH2TH2867Y NOW33332106Yo You Baby TH2TH3867Y NOW33332106No Way Out TH2TH9867Y NOW33332106Can't find it TJ2TJ2872N WOW33332017sure thing alas TJ2TJ3872N WOW33332017the sky rocks TJ2TJ4872N WOW33332017nothing else matters ... (4 Replies)
Discussion started by: devtakh
4 Replies

8. 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

9. Shell Programming and Scripting

awk sed parsing

hi , i would like to parse some file with the fallowing data : data data data "unwanted data" data data "unwanted data" data data data data #unwanted data. what i want it to have any coments between "" and after # to be erased using awk or/and sed. has anyone an idea? thanks. (3 Replies)
Discussion started by: Darsh
3 Replies

10. Shell Programming and Scripting

awk parsing problem

I need help with a problem that I have not been able to figure out. I have a file that is about 650K lines. Records are seperated by blank lines, fields seperated by new lines. I was trying to make a report that would add up 2 fields and associate them with a CP. example output would be... (11 Replies)
Discussion started by: timj123
11 Replies
Login or Register to Ask a Question