|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
sed/awk script to parse list of bandwidth rules
Hello all gurus, I have a long list of rules as below: Code:
20 name:abc addr:203.45.247.247/255.255.255.255 WDW-THRESH:12 BW-OUT:10000000bps BW-IN:15000000bps STATSDEVICE:test247 STATS:Enabled (4447794/0) <IN OUT> 25 name:xyz160 addr:203.45.233.160/255.255.255.224 STATSDEVICE:test160 STATS:Enabled priority:pass-thru (1223803328/0) <IN OUT> 37 name:testgrp2 <B> WDW-THRESH:8 BW-BOTH:192000bps STATSDEVICE:econetgrp2 STATS:Enabled (0/0) <Group> START:NNNNNNN-255-0 STOP:NNNNNNN-255-0 62 name:blahblahl54 addr:203.45.225.54/255.255.255.255 WDW-THRESH:5 BWLINK:cbb256 BW-BOTH:256000bps STATSDEVICE:hellol54 STATS:Enabled (346918/77) <IN OUT> Using SED or AWK or combination of both, can I get output like below: Code:
20 15000000 10000000 25 37 192000 62 256000 Basically the rule number, followed by the value after BW-IN and followed by the value after BW-OUT and rule number, followed by the value BW-BOTH and just the rule number, if there are no BW-OUT, BW-IN and BW-BOTH The rule line contains either BW-BOTH or BW-OUT and BW-IN. But never all three. Thank you so much for your valuable time. sb245 Last edited by Franklin52; 06-25-2012 at 09:48 AM.. Reason: Please use code tags for data and code samples |
| Sponsored Links | ||
|
|
#2
|
|||
|
|||
|
Try this: Code:
awk '
{s=$1}
{
for(i=2;i<=NF;i++){
if($i ~ "BW-"){
sub("BW-.*:",x,$i)
sub("bps$",x,$i)
s=s FS $i
}
}
}
{print s}' file |
| Sponsored Links | ||
|
|
#3
|
||||
|
||||
|
Code:
$ awk -F"[: ]" '{out=$1; for(i=2;i<=NF;i++)if($i~/bps/){sub("bps","",$i);out=out" "$i} print out;out=""}' input.txt
20 10000000 15000000
25
37 192000
62 256000 |
| The Following User Says Thank You to itkamaraj For This Useful Post: | ||
sb245 (06-25-2012) | ||
|
#4
|
|||
|
|||
|
Thank you itkamaraj. It is working. But can you modify the script so that the value after BW-IN: is printed in the 2nd column. Code:
20 15000000 10000000 The 1st col: rule number The 2nd col: BW-IN value or the BW-BOTH value The 3rd col: BW-OUT value Thank you for your input. sb Last edited by sb245; 06-26-2012 at 06:37 AM.. Reason: a little modification needed in the answered script |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Help parse comma separated list | NoMadBanker | Shell Programming and Scripting | 11 | 10-26-2010 02:28 PM |
| Parse an XML task list to create each task.xml file | MissI | Shell Programming and Scripting | 3 | 11-11-2008 01:20 PM |
| How to parse a list of data to find the missin stats. | asirohi | Shell Programming and Scripting | 3 | 08-08-2008 12:06 PM |
| Script to parse an access-list | philipz | Shell Programming and Scripting | 25 | 07-11-2008 04:46 AM |
| how do i get current bandwidth usage via shell script? | scarfake | Shell Programming and Scripting | 2 | 05-25-2008 10:27 PM |
|
|