LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Get number between / / (https://www.linuxquestions.org/questions/linux-newbie-8/get-number-between-791839/)

icygalz 02-26-2010 05:53 PM

Get number between / /
 
Hi,

i have:

avg = 97.384/97.799/98.561/0.539 ms

And I want to get the result

avg= 97.799 ms

I am confused how to do it directly so I am planning to erase the first number and slash so it will look like this

avg = 97.799/98.561/0.539 ms

by

Code:

sed 's@=.*/@ @g'
but it is giving strange output

avg 0.296 ms


Can anyone help me?

Thanks

smeezekitty 02-26-2010 06:01 PM

sed 's/\//\n/g' | head -n 2 | tail -n 1

Tinkster 02-26-2010 07:02 PM

Quote:

Originally Posted by icygalz (Post 3878274)
Hi,

i have:

avg = 97.384/97.799/98.561/0.539 ms

And I want to get the result

avg= 97.799 ms

I am confused how to do it directly so I am planning to erase the first number and slash so it will look like this

avg = 97.799/98.561/0.539 ms

by

Code:

sed 's@=.*/@ @g'
but it is giving strange output

avg 0.296 ms


Can anyone help me?

Thanks

Almost, slightly oversimplified. Not sure where the 0.296
might have come from, if I run your example it gives:
Code:

avg  0.539 ms
which is in line with your input.

Try
Code:

  echo "avg = 97.384/97.799/98.561/0.539 ms" |sed -r 's@ = [^/]+/([^/]+).*@= \1 ms@'
avg= 97.799 ms


icygalz 02-26-2010 08:35 PM

Thanks guys^_^

schneidz 02-26-2010 08:39 PM

Code:

avg=`echo 97.384/97.799/98.561/0.539 ms | awk -F / '{print $2}'`


All times are GMT -5. The time now is 05:21 AM.