Parse data


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Parse data
# 1  
Old 05-07-2012
Parse data

Guys , please help me out with another AWK solution ...

Input
Code:
 
Device Physical Name     : Not Visible
Device Symmetrix Name    : 0743
Front Director Paths (2):
        {
        ----------------------------------------------------------------------
                                 POWERPATH  DIRECTOR   PORT             LUN   
                                 --------- ----------  ---- -------- ---------
        PdevName                 Type      Type Num    Sts  VBUS TID SYMM Host
        ----------------------------------------------------------------------
        Not Visible              N/A       FA   03H:0  RW   000  00  012  N/A
        Not Visible              N/A       FA   14H:0  RW   000  00  012  N/A
        }
RDF Information
        {
        Device Symmetrix Name                  : 0743
        RDF Type                               : R1
        RDF (RA) Group Number                  : 33                (20)
        Remote Device Symmetrix Name           : 1B85
        Remote Symmetrix ID                    : 000192601512
        RDF Mode                               : Asynchronous
 
        RDF Pair State (  R1 <===> R2 )        : Consistent
 RDF Information
        {
        Device Symmetrix Name                  : 0743
        RDF Type                               : R1
        RDF (RA) Group Number                  : 99                (62)
        Remote Device Symmetrix Name           : 0883
        Remote Symmetrix ID                    : 000192604766
        RDF Mode                               : Synchronous
 
       RDF Pair State (  R1 <=\=> R2 )        : Split

Ouput needed
Code:
 
Device Symmetrix Name ,[Front Director Paths],[Remote Device Symmetrix Name Remote Symmetrix ID  RDF (RA) Group Number  RDF Mode RDF Pair State]
0743,[03H:0 14H:0],[1B85 000192601512 33 Asynchronous Consistent],[0883 000192604766  99 Synchronous Split]

Thanks
# 2  
Old 05-08-2012

What needs to be done to the input to get the output?
# 3  
Old 05-09-2012
Input is basically my reference file which i need to parse most likely using Awk to get the desired output .need to find all the fields in red and format them to get the output as above .Hope it is clear ...thx
# 4  
Old 05-24-2012
I am still stuck with this issue , will appreciate any help ..... thx
# 5  
Old 06-04-2012
This works to some extent , but i cannot figure out the "Front Director Paths " part
Also how do i make number of records dynamic ? , for example the input file can have more than 2 records ....

Code:
 
nawk 'BEGIN{print "Device Symmetrix Name,[Front Director Paths],[Remote Name   Remote Symm   Group Number   Mode  State ],[Remote Name   Remote Symm   Group Num
ber   Mode  State ]"}
/^Device Symmetrix Name/{a=$NF}  /Group Number/{d[++i]=$NF} /Remote Device Symmetrix Name/{c[i]=$NF} 
/Remote Symmetrix ID/{e[i]=$NF} /Mode/{f[i]=$NF}
/State/{g[i]=$NF;p++} p==2{print a,"[" c[1]"\t"d[1]"\t"e[1]"\t"f[1]"\t"g[1]"] ","[" c[2]"\t"d[2]"\t"e[2]"\t"f[2]"\t"g[2]"]" ;i=p=0;}
' OFS=, /tmp/input


Output

Code:
 
Device Symmetrix Name,[Remote Name   Remote Symm   Group Number   Mode  State ],[Remote Name   Remote Symm   Group Number   Mode  State ]
0743,[1B85      33      000192601555    Asynch  Consistent] ,[1BBB      55      000192601333    Synch   Split]

# 6  
Old 06-05-2012
This is how I would do it:

Code:
awk '
    function print_stuff(   i )
    {
        printf( "Device Symmetrix Name,[Front Director Paths]" );       # header with one 'section' for each RDF section
        for( i = 1; i <= rdf_idx; i++ )
            printf( ",[Remote Name   Remote Symm   Group Number   Mode  State ]" );
        printf( "\n" );

        printf( "%s,[", dsn );                              # data line; one section for each RDF
        for( i = 1; i <= fdp_idx; i++ )
            printf( "%s%s", i > 1 ? " " : "", fdp[i] );
        for( i = 1; i <= rdf_idx; i++ )
            printf( "%s,[%s %s %s %s %s]", i == 1 ? "]" : "", rdf[i,4], rdf[i,5], rdf[i,3], rdf[i,6], rdf[i,7]  );
        printf( "\n" );
    }

    /---/ || /{/  ||  NF < 1 { next; }                      # ignore these lines
    /Device Physical Name/ {                                # new major section
        if( dsn )
            print_stuff( );                                 # print last gathered data and reset indexes
        dsn = "";
        fdp_idx = 0;
        rdf_idx = 0;
        next;
    }
    /Device Symmetrix Name/  && dsn == "" { dsn = $NF; next; }
    /PdevName/ { fd_snarf = 1; next; }                      # safe to capture fdp data

    /}/ { fd_snarf = 0; next; }                             # stop capturing fdp data
    fd_snarf { fdp[++fdp_idx] = $(NF-5); next; }

    /RDF Information/ { rdf_sidx=1; rdf_idx++; rdf_snarf=1; next; }
    rdf_snarf {                                             # capture all RDF lines, but we will only print some
        n = split( $0, a, ":" );
        split( a[n], b, " " );
        rdf[rdf_idx,rdf_sidx++] = b[1];
        next;
    }

    END { print_stuff( ); }                                 # final print of last major section
' input-file >output-file



It will capture 1 or more RDF information sections, and one or more front descriptor paths. It will also capture more than one 'major section' if there are multiple instances of the section you pasted.

Hope this at least gets you started.
This User Gave Thanks to agama 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

Need a script to parse data and output to csv

I am not too savvy with arrays and am assuming that what I am looking for needs arrays. This is my requirement. So I have the raw data that gets updated to a log as shown below StudentInfo: FullInfo = { Address = Newark Age = 20 Name= John } StudentInfo:... (2 Replies)
Discussion started by: sidnow
2 Replies

2. Solaris

Need command to parse data

Hi Friends, I have data like below t064266 I want output into this format t064266 Data are space delimited and i want parse third column data. Thanks (9 Replies)
Discussion started by: Jagaat
9 Replies

3. Shell Programming and Scripting

Perl :: to parse the data from a string.

Hi folks, I have a line in log from which I need to parse few data. Jul 6 00:05:58 dg01aipagnfe01p %FWSM-3-106011: Deny inbound (No xlate) From the above... I need to parse the %FWSM-3-106011: substring. Another example Jul 13 00:08:55 dq01aipaynas01p %FWSM-6-302010: 2 in use, 1661... (3 Replies)
Discussion started by: scriptscript
3 Replies

4. Shell Programming and Scripting

Regex to Parse data

Experts and Informed folks, Need some help here in parsing the log file. 1389675 Opera_ShirtCatalog INSERT INTO Opera_ShirtCatalog(COL1, COL2) VALUES (1, 'TEST1'), (2,'TEST2'); 1389685 Opera_ShirtCatlog_Wom INSERT INTO Opera_ShirtCatlog_Wom(col1, col2, col3) VALUES (9,'Siz12, FormFit',... (12 Replies)
Discussion started by: ManoharMa
12 Replies

5. Shell Programming and Scripting

Parse data

hi i have a file p1.htm <div class="colorID2"> aaaa aaaa aa <br/> bbbbbbbb bbb<br/> <br/>cccc ccc ccc </div><div class="colorID1"> dddd d ddddd<br/> eeee eeee eeeeeeeeee<br/> fffff <br/>g gg<br/> (5 Replies)
Discussion started by: saw7
5 Replies

6. Shell Programming and Scripting

How to parse data?

Hi all, I have output of paction command looking like this: RELCI 0 IP address 1.2.16.3 Xmit: CURRENT Recv: WAIT_HEADER 0 congestions 2617/0 buf. sent/rec Xmit: CURRENT Recv: WAIT_HEADER 0 congestions 0/0 buf. sent/rec BUFFER Xmit: ... (6 Replies)
Discussion started by: sameucho
6 Replies

7. Shell Programming and Scripting

Extract and parse data between two strings

Hi , I have a billing CDR file which is separated by “!”. I need to extract and format data between the starting (“!”) and the end of the line (“1.2.1.8”). These two variables are permanent tags to show begin and end. ! TICKET NBR : 2 ! GSI : 101 ! 3100.2.112.1 24/03/2010 00:41:14 !... (3 Replies)
Discussion started by: jaygamini
3 Replies

8. Shell Programming and Scripting

parse data using sh script

Hi, I am a newbie to unix/shell scripting and i have a question on how to parse a txt file using perl in a sh script. I have a txt file that contains hundreds of lines with data like this.... X, Y, Latitude, Longitude 1, 142, -38.000000, -91.000000, 26.348 2, 142, 60.000000, -90.000000,... (2 Replies)
Discussion started by: moonbaby
2 Replies

9. UNIX for Dummies Questions & Answers

How to parse the specific data from the file

Hi, I need to parse this data FastEthernet0/9,|FastEthernet0/10,|FastEthernet0/11,FastEthernet0/13|, FastEthernet0/12,FastEthernet0/24 . and get only the value like e.g 0/24,0/11. how to do this in shell script. Thanks in Advance. (2 Replies)
Discussion started by: MuthuAlagappan
2 Replies

10. Shell Programming and Scripting

Parse a range of data

Hello, I have a file which has a range of date like: 00:00 test 00:01 test2 00:02 test3 00:03 test4 00:04 test5 00:05 test6 Using input (stdin) i would like to parse the data 00:01 to 00:04. The output file should be like this: 00:01 test2 00:02 test3 00:03 test4 00:04 test5 ... (5 Replies)
Discussion started by: BufferExploder
5 Replies
Login or Register to Ask a Question