Help with parsing data with awk , eliminating unwanted data


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with parsing data with awk , eliminating unwanted data
# 1  
Old 01-04-2013
Help with parsing data with awk , eliminating unwanted data

Experts ,

Below is the data:
Code:
--- Physical volumes ---
PV Name /dev/dsk/c1t2d0
VG Name /dev/vg00
PV Status available
Allocatable yes
VGDA 2
Cur LV 8
PE Size (Mbytes) 8
Total PE 4350
Free PE 2036
Allocated PE 2314
Stale PE 0
IO Timeout (Seconds) default

--- Physical volumes ---
PV Name /dev/dsk/c1t2d1
VG Name /dev/vg01
PV Status available
Allocatable yes
VGDA 2
Cur LV 8
PE Size (Mbytes) 8
Total PE 43500
Free PE 20366
Allocated PE 2314
Stale PE 0
IO Timeout (Seconds) default

--- Physical volumes ---
PV Name /dev/dsk/c1t2d4
VG Name /dev/vg02
PV Status available
Allocatable yes
VGDA 2
Cur LV 8
PE Size (Mbytes) 8
Total PE 435044
Free PE 203645
Allocated PE 2314
Stale PE 0
IO Timeout (Seconds) default

--- Physical volumes ---
PV Name /dev/dsk/c1t2d5
VG Name /dev/vg03
PV Status available
Allocatable yes
VGDA 2
Cur LV 8
PE Size (Mbytes) 8
Total PE 435080
Free PE 2036890
Allocated PE 2314
Stale PE 0
IO Timeout (Seconds) default


I want the output as below: with "VG Name , PE Size ,Free PE" values to be printed side by side:

Code:
/dev/vg00 8 2036
/dev/vg01 8 20366
/dev/vg02 8 203645
/dev/vg03 8 2036890


Thank you,
# 2  
Old 01-04-2013
Code:
 $ nawk '/VG Name/{v=$NF}/PE Size/{ps=$NF}/Free PE/{fp=$NF}fp{print v,ps,fp;fp="";}' input.txt
/dev/vg00 8 2036
/dev/vg01 8 20366
/dev/vg02 8 203645
/dev/vg03 8 2036890

if you dont have nawk, then use awk
This User Gave Thanks to itkamaraj For This Post:
# 3  
Old 01-04-2013
Since the output appears to have a strict format you could also try:
Code:
awk '{print $10, $24, $30}' RS= infile

But that would probably be more sensitive in case of possible future changes in the output of the command..

Last edited by Scrutinizer; 01-04-2013 at 03:49 AM..
This User Gave Thanks to Scrutinizer For This Post:
# 4  
Old 01-05-2013
itkamaraj ,

It works fine, thanks, However I am unable to understand
Code:
{fp=$NF}fp{print v,ps,fp;fp="";}'

part in the code , why you are using two times fp variable.
Appreciate if you could explain it.


Scrutinizer,
Nice , Thanks it works fine for the data . But If I have a data of huge length sa 1000 lines , the parsing with field number would be difficult in that way I think. Or is there any trick for a bigger data in the filed number wise.

Thanks,
# 5  
Old 01-05-2013
Hi reveri,

Setting RS to the empty string is a special condition where records are split if there are two consecutive newlines. There would not be a limit on the number of records.

There would be a limitation per record, if the record exceeds the maximum length, which would not happen very quickly, but in the awk version of HP-UX (that is what I think this it, right? ) sooner than on some other platforms..

--
{fp=$NF} belongs to the preceding condition-action pair.

fp{print v,ps,fp;fp="";}' means if fp is neither empty nor zero then process {print v,ps,fp;fp="";}

--
Here is another version without RS=
Code:
awk '/VG Name/{a=$NF} /PE Size/{b=$NF} /Free PE/{print a,b,$NF}' infile

or
Code:
awk '/VG Name|PE Size|Free PE/{printf "%s ", $NF} /Free PE/{print x}' infile


Last edited by Scrutinizer; 01-06-2013 at 03:18 AM..
This User Gave Thanks to Scrutinizer For This Post:
# 6  
Old 01-06-2013
Scrutinizer,
Thanks, yes it was from hp-ux ,

Thanks for the time, detail and explaining,
Reveri.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk --> math-operation in data-record and joining with second file data

Hi! I have a pretty complex job - at least for me! i have two csv-files with meassurement-data: fileA ...... (2 Replies)
Discussion started by: IMPe
2 Replies

2. Shell Programming and Scripting

Parsing XML (and insert data) then output data (bash / Solaris)

Hi folks I have a script I wrote that basically parses a bunch of config and xml files works out were to add in the new content then spits out the data into a new file. It all works - apart from the xml and config file format in the new file with XML files the original XML (that ends up in... (2 Replies)
Discussion started by: dfinch
2 Replies

3. Shell Programming and Scripting

Parsing cron data with awk

Heya, I'm currently working on a script so I can see which cron jobs, if any, on a system are executing less frequently than 15 minutes (1 - 14 minutes). This is the only data I'm interested in. So far I have the following: #!/bin/bash IFS=$'\n';for line in `ls -f /var/spool/cron/*`; do... (5 Replies)
Discussion started by: Elvirnith
5 Replies

4. UNIX for Dummies Questions & Answers

Deleting the unwanted data based on condition

hi i have my input data like this aaa bbb ccc asa dff nmj mnj saa dff oik aax cdx saa oik asq sdf dssi want my output file to be like this mnj saa dff oik aax cdx saa oiki want to retain only those lines which will have oik just below them and i want oik to be as next column to those... (1 Reply)
Discussion started by: anurupa777
1 Replies

5. Shell Programming and Scripting

Help in Parsing data

I have below string Transaction_ID:SDP-DM-151204679 , Transaction_DateTime:2011-02-11 00:00:15 GMT+05:30 , Transaction_Mode:WAP , Circle_ID:4 , Circle_Name:BJ ,Zone: , CustomerID:B_31563486 , MSISDN:7870904329 , IMSI:405876122068099 , IMEI: , Sub_Profile:Pre-Paid , CPID:Nazara , CPNAME:Nazara ,... (6 Replies)
Discussion started by: poweroflinux
6 Replies

6. Shell Programming and Scripting

Extract data based on match against one column data from a long list data

My input file: data_5 Ali 422 2.00E-45 102/253 140/253 24 data_3 Abu 202 60.00E-45 12/23 140/23 28 data_1 Ahmad 256 7.00E-45 120/235 140/235 22 data_4 Aman 365 8.00E-45 15/65 140/65 20 data_10 Jones 869 9.00E-45 65/253 140/253 18... (12 Replies)
Discussion started by: patrick87
12 Replies

7. Shell Programming and Scripting

Question about Awk for Data Parsing

Hi, I am doing some data parsing for some economics research. I was recently exposed to shell script and am brand new to awk. I have a large csv file (like 10G) and I would like to make it a lot smaller with awk, but it is a bit tricky for me and I haven't been able to get it yet. I would... (5 Replies)
Discussion started by: EconResearch
5 Replies

8. Shell Programming and Scripting

Eliminate unwanted data

Hi, I am stuck on writing a script that reads a file, retains wanted data but discards unwanted data from a CSV file. This is a sample of my table {not the actual data) ID Color tel_num Name color2 color3 abcdef green 5551212 jj88 red blue acbdfe yellow... (5 Replies)
Discussion started by: t524ube
5 Replies

9. Shell Programming and Scripting

Remove unwanted data?

Hi Can any one help me remove the unwanted data? I would want to remove the complete event id 4910 ( the type there is INFO), that means, I have to remove starting from 7th - 19th lines. can any one of you please help? Thanks, (24 Replies)
Discussion started by: hitmansilentass
24 Replies

10. UNIX for Dummies Questions & Answers

Parsing XML dynamic data via awk?

I am trying to use a line of output in an XML file as input in another new XML file for processing purposes via a shell script. Since I am a newbie though, I'm not sure how to do this since the data is different everytime. I am using this technique with static data right now: echo -n "Running... (5 Replies)
Discussion started by: corwin43
5 Replies
Login or Register to Ask a Question