The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Extracting lines between 2 strings only if the pattern patches simran Shell Programming and Scripting 5 04-23-2008 01:58 PM
extracting a set of strings from a text file Deanne Shell Programming and Scripting 2 09-20-2007 08:31 PM
Extracting the lines between 2 strings of a file babloo Shell Programming and Scripting 2 02-14-2007 07:27 AM
Help with extracting strings from a file cmsdelhi Shell Programming and Scripting 7 01-12-2007 05:49 AM
Extracting strings hugow UNIX for Dummies Questions & Answers 1 06-24-2005 03:09 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-26-2008
Registered User
 

Join Date: May 2008
Posts: 13
extracting numbers from strings

Hello all,

I am being dumb with this and I know there is a simple solution.

I have a file with the follwing lines

Code:
 bc stuff (more)...............123
 bc stuffagain (moretoo)............0
 bc stuffyetagain (morehere)......34
 failed L3 thing..............1
 failed this status.............24
 failed that status.............253
 failed some kind of check........0
I want to pull the numbers off the end of the lines. I can use cut but that is not very robust. I have been using sed but cannot get it to work properly.

I don't think this is very hard. It's been a long day.

Thanks!

gobi

Last edited by Yogesh Sawant; 05-26-2008 at 11:01 PM. Reason: added code tags
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 05-26-2008
jaduks's Avatar
Registered User
 

Join Date: Aug 2007
Location: Assam,India
Posts: 145
If you just want to extract the last field:
Code:
$ sed -n 's/.*\.//;p' gobi.txt
or
$ awk 'BEGIN{FS="."} {print $NF}' gobi.txt
And to extract the digits:

Code:
$ sed 's/.*\.\.\([0-9]*\).*/\1/' gobi.txt
//Jadu
Reply With Quote
  #3 (permalink)  
Old 05-26-2008
Registered User
 

Join Date: May 2008
Posts: 13
yes thank you.

I left out the \.\. from the sed command. like I said its been a long day.

Thanks!
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 06:10 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0