hi .. i need a shell function to index a string ....
hi...
can somebody help me ... if i echo ping -c1 www.tiberiansun.com i get PING www.tiberiansun.com \(209.85.147.104\) 56\(84\) bytes of data.--- google.de ping statistics ---1 packets transmitted, 0 recieved, 100% packet loss, time 13ms i want to extract the part of time 13ms after the string .... if i use echo `expr index "$str1" "time"` i get always 11 ... can somebody help me plz? the entire script? |
Quote:
Post what you've written so far, because just seeing that one line with no context above it doesn't indicate why it's not working, since we don't know what "str1" is being set and how. If I had to write the function, I'd pipe the ping output into grep for "time=", then use awk and split on the "=" character, and get the time from that. |
From the expr man page:
Code:
index STRING CHARS Try using expr substr instead of expr index or bash parameter expansion: Code:
time=${str1##*time } |
Moved: This thread is more suitable in <Programming> and has been moved accordingly to help your thread/question get the exposure it deserves.
|
I am curious why you would echo the output of the ping command seeing it will already display its own output?
|
All times are GMT -5. The time now is 05:49 PM. |