How to write such kind of script?
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix administration > How to write such kind of script?




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    How to write such kind of script?  
yezi


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
06-06-06 12:21 AM

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






[ Post a follow-up to this message ]



    Re: How to write such kind of script?  
Bit Twister


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
06-06-06 12:21 AM

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





[ Post a follow-up to this message ]



    Re: How to write such kind of script?  
Logan Shaw


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
06-06-06 06: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





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 11:58 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register