|
Home > Archive > Unix administration > June 2006 > How to write such kind of script?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
How to write such kind of script?
|
|
|
| Dear all:
I try to code script to realize function which is described as after:
I have tons of fles which is end with *.ping, try to parse out 2
parameters from the last line of each file. The sentence is like as
following :
rtt min/avg/max/mdev = 136.200/136.643/137.152/0.612 ms, pipe 2
The two paremeters are :
1> avg , which is 136.643
2> mdev, which is 0.612
Thanks for any hint.
bin
| |
| Bit Twister 2006-06-05, 7:21 pm |
| On 5 Jun 2006 13:23:48 -0700, yezi wrote:
> Dear all:
>
> I try to code script to realize function which is described as after:
>
> I have tons of fles which is end with *.ping, try to parse out 2
> parameters from the last line of each file. The sentence is like as
> following :
>
> rtt min/avg/max/mdev = 136.200/136.643/137.152/0.612 ms, pipe 2
>
> The two paremeters are :
>
> 1> avg , which is 136.643
> 2> mdev, which is 0.612
>
> Thanks for any hint.
#***************************************
************
# just a hint then
_ifs_bkup=$IFS
line="rtt min/avg/max/mdev = 136.200/136.643/137.152/0.612 ms, pipe 2"
IFS=" /"
set -- $(echo $line)
shift 6
echo avg=$2 mdev=$4
IFS=$_ifs_bkup
#***************************************
************
For extra points
! bash script advanced documentation
http://tldp.org/LDP/abs/html/index.html
! bash script introduction to Linux documentation
http://tldp.org/LDP/intro-linux/html/index.html
| |
| Logan Shaw 2006-06-06, 1:27 am |
| yezi wrote:
> Dear all:
>
> I try to code script to realize function which is described as after:
>
> I have tons of fles which is end with *.ping, try to parse out 2
> parameters from the last line of each file. The sentence is like as
> following :
>
> rtt min/avg/max/mdev = 136.200/136.643/137.152/0.612 ms, pipe 2
>
> The two paremeters are :
>
> 1> avg , which is 136.643
> 2> mdev, which is 0.612
To get only the lines you care about :
grep 'min/avg/max/dev' *.ping
To parse a value from each line, pipe the line into awk to get just
the series of numbers:
awk '{print $4}'
Then use cut to get only the one you care about :
cut -d/ -f2 (for avg)
cut -d/ -f4 (for mdev)
For example, to get the avg from all the files:
grep 'min/avg/max/dev' *.ping | awk '{print $4}' | cut -d/ -f2
Hope that helps.
- Logan
|
|
|
|
|