Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Capture with sed? 3

Status
Not open for further replies.
May 29, 2003
40
US
Hi all,

I have an input file contaning the following string:

"--- 100.100.100.1 ping statistics ---
5 packets transmitted, 5 received, 0% loss, time 4003ms
rtt min/avg/max/mdev = 0.711/0.939/1.716/0.391 ms"

From my bash script i would like to capture the loss (%) precent valu from the file above.

i've tried doing it with this sed format but it didn't work:
sed 's/^.*received, \([^;]*\);.*/\1/g'

Anyone please could advise how to capture the loss value using sed or anything else which could be more appropriate here.

thanks allot.
 
This is a bit ugly but it will work.

grep '%' <input file name>| sed 's/^.*recieved,//g'|sed 's,.*$//g'


The result of this was - 0% loss

If someone else has a cleaner method I would be more than happy to see it.

Just remember by default every line of input that is passed to sed will become a line of output unless you use the -n to surpress the lines of data from the input file.
 
something like that:

sed -ne 's/.*\([0-9][0-9]*\)%.*loss.*/\1/p' youFile.txt

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
moonlight1, simply replace the two semi-colons (;) by a comma (,) in your sed script.

Hope This Help
PH.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top