How to parse data?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to parse data?
# 1  
Old 06-04-2010
How to parse data?

Hi all,

I have output of paction command looking like this:

Code:
RELCI 0 IP address 1.2.16.3
  [SIG ] Xmit: CURRENT           Recv: WAIT_HEADER            0 congestions 2617/0 buf. sent/rec
  [CHAR] Xmit: CURRENT           Recv: WAIT_HEADER            0 congestions 0/0 buf. sent/rec
  BUFFER Xmit:     1022/1024     Recv:        4/4
  PDP    attached: 0  waiting[high/low] : 0/0
  Bad Xref counter: 0
  No congestion

RELCI 1 IP address 1.2.16.4
  [SIG ] Xmit: CURRENT           Recv: WAIT_HEADER            0 congestions 0/0 buf. sent/rec
  [CHAR] Xmit: CURRENT           Recv: WAIT_HEADER            0 congestions 0/0 buf. sent/rec
  BUFFER Xmit:     1022/1024     Recv:        4/4
  PDP    attached: 0  waiting[high/low] : 0/0
  Bad Xref counter: 0
  No congestion

RELCI 2 IP address 1.2.16.5
  [SIG ] Xmit: CURRENT           Recv: WAIT_HEADER            0 congestions 0/0 buf. sent/rec
  [CHAR] Xmit: CURRENT           Recv: WAIT_HEADER            0 congestions 0/0 buf. sent/rec
  BUFFER Xmit:     1022/1024     Recv:        4/4
  PDP    attached: 0  waiting[high/low] : 0/0
  Bad Xref counter: 0
  No congestion

RELCI 3 IP address 1.2.16.2
  [SIG ] Xmit: CURRENT           Recv: HEADER_READING         0 congestions 47/42 buf. sent/rec
  [CHAR] Xmit: CURRENT           Recv: WAIT_HEADER            0 congestions 8/0 buf. sent/rec
  BUFFER Xmit:     1022/1024     Recv:        3/4
  PDP    attached: 1  waiting[high/low] : 0/0
  Bad Xref counter: 0
  No congestion

RELCI 4 IP address 1.2.16.131
  [SIG ] Xmit: CURRENT           Recv: WAIT_HEADER            0 congestions 0/0 buf. sent/rec
  [CHAR] Xmit: CURRENT           Recv: WAIT_HEADER            0 congestions 0/0 buf. sent/rec
  BUFFER Xmit:     1022/1024     Recv:        4/4
  PDP    attached: 0  waiting[high/low] : 0/0
  Bad Xref counter: 0
  No congestion

RELCI 5 IP address 1.2.16.130
  [SIG ] Xmit: CURRENT           Recv: WAIT_HEADER            0 congestions 0/0 buf. sent/rec
  [CHAR] Xmit: CURRENT           Recv: WAIT_HEADER            0 congestions 0/0 buf. sent/rec
  BUFFER Xmit:     1022/1024     Recv:        4/4
  PDP    attached: 0  waiting[high/low] : 0/0
  Bad Xref counter: 0
  No congestion

RELCI 6 IP address 1.2.16.132
  [SIG ] Xmit: CURRENT           Recv: WAIT_HEADER            0 congestions 0/0 buf. sent/rec
  [CHAR] Xmit: CURRENT           Recv: WAIT_HEADER            0 congestions 0/0 buf. sent/rec
  BUFFER Xmit:     1022/1024     Recv:        4/4
  PDP    attached: 0  waiting[high/low] : 0/0
  Bad Xref counter: 0
  No congestion

RELCI 7 IP address 1.2.16.133
  [SIG ] Xmit: CURRENT           Recv: WAIT_HEADER            0 congestions 0/0 buf. sent/rec
  [CHAR] Xmit: CURRENT           Recv: WAIT_HEADER            0 congestions 0/0 buf. sent/rec
  BUFFER Xmit:     1022/1024     Recv:        4/4
  PDP    attached: 0  waiting[high/low] : 0/0
  Bad Xref counter: 0
  No congestion

I need a script which gives me the IP address of the block in which PDP attached <> 0. How to do that please?
Regards
# 2  
Old 06-04-2010
Code:
awk '!/PDP    attached: 0/ { print $5 }' RS= infile


Use /usr/xpg4/bin/awk or nawk on Solaris.


Edit: Sorry, just saw the OP wants only the IP ..., corrected.

Last edited by radoulov; 06-04-2010 at 08:10 AM..
This User Gave Thanks to radoulov For This Post:
# 3  
Old 06-04-2010
Code:
awk 'BEGIN{RS="\n\n"} /PDP\W+attached: [^0]/ {print $5;}' output.file

# 4  
Old 06-04-2010
Thank you.

Both solution works - thanks a lot - but both I don't fully understand it Smilie Would you give please some short explanation too?

What's about the second one, I don't even know how to adapt it if I don't want to read from file but use output of some command (called paction in my case). The first one I adapted this way:

Code:
paction 127.0.0.1 show relc | awk '/PDP    attached: 0/ { print $5 }' RS=

but the same doesn't work for the secondf one.

Last edited by sameucho; 06-04-2010 at 09:59 AM..
# 5  
Old 06-04-2010
Setting RS to "\n\n" splits the file to records separated by empty line. Then awk checks if in any of those records is string matching regular expression placed between //, and if it matches then 5th field from that record is printed. Fields are separated by space by default, so IP address is printed. As for using my one-liner to work with command output, just omit filename, and pipe output into it like that:
Code:
paction 127.0.0.1 show relc | awk 'BEGIN{RS="\n\n"} /PDP\W+attached: [^0]/ {print $5;}'

This User Gave Thanks to bartus11 For This Post:
# 6  
Old 06-04-2010
Tahank you once more. I see I will have to find some time to learn AWK.
# 7  
Old 06-04-2010
Quote:
Originally Posted by bartus11
Code:
awk 'BEGIN{RS="\n\n"} /PDP\W+attached: [^0]/ {print $5;}' output.file

It would probably not be a bad idea to use the command name "gawk", as I don't think that will work on any other implementation. That value of RS and the "\W" character class-like escape sequence are both gawk extensions. For a portable approach, see radoulov's solution.

Quote:
Originally Posted by http://www.opengroup.org/onlinepubs/9699919799/utilities/awk.html

RS
The first character of the string value of RS shall be the input record separator; a <newline> by default. If RS contains more than one character, the results are unspecified. If RS is null, then records are separated by sequences consisting of a <newline> plus one or more blank lines, leading or trailing blank lines shall not result in empty records at the beginning or end of the input, and a <newline> shall always be a field separator, no matter what the value of FS is.
I mention this only as a heads up to less experienced AWKers, in case implementation portability is a concern.

Regards,
Alister
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

Guys , please help me out with another AWK solution ... Input Device Physical Name : Not Visible Device Symmetrix Name : 0743 Front Director Paths (2): { ---------------------------------------------------------------------- ... (5 Replies)
Discussion started by: greycells
5 Replies

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

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