LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-26-2010, 05:53 PM   #1
icygalz
LQ Newbie
 
Registered: Feb 2010
Posts: 3

Rep: Reputation: 0
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
 
Old 02-26-2010, 06:01 PM   #2
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,339

Rep: Reputation: 231Reputation: 231Reputation: 231
sed 's/\//\n/g' | head -n 2 | tail -n 1

Last edited by smeezekitty; 02-26-2010 at 06:17 PM. Reason: Fixed sed syntax
 
Old 02-26-2010, 07:02 PM   #3
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Quote:
Originally Posted by icygalz View Post
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

Last edited by Tinkster; 02-26-2010 at 07:04 PM.
 
1 members found this post helpful.
Old 02-26-2010, 08:35 PM   #4
icygalz
LQ Newbie
 
Registered: Feb 2010
Posts: 3

Original Poster
Rep: Reputation: 0
Thanks guys^_^
 
Old 02-26-2010, 08:39 PM   #5
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

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


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
why sector number not match block number? bitzsk Linux - Kernel 1 06-09-2009 05:32 AM
How to grab one number from a row in a text but not another number Mike_V Programming 9 04-25-2009 04:57 AM
adding constant (number) to a number in all rows skuz_ball Programming 2 05-20-2008 09:57 PM
how do you edit your virtual console number? (or VT number 3) jjorloff1 Linux - General 2 04-03-2004 07:21 PM
why there is a need for minor number and major number for monitor/keyboard in pc? tripathi Solaris / OpenSolaris 1 11-07-2003 09:36 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:27 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration