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 and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
sed: Find start of pattern and extract text to end of line, including the pattern TestTomas Shell Programming and Scripting 5 05-27-2009 12:16 PM
pattern extract priyam Shell Programming and Scripting 6 10-20-2008 11:15 AM
nawk-how count the number of occurances of a pattern, when don't know the pattern cyber111 Shell Programming and Scripting 2 05-11-2008 04:00 AM
Extract the Pattern aajan UNIX for Dummies Questions & Answers 6 08-08-2007 05:47 AM
Please help! Sed extract a pattern zhen Shell Programming and Scripting 11 09-18-2006 01:36 PM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-02-2009
aoussenko aoussenko is offline
Registered User
  
 

Join Date: May 2008
Posts: 119
How to extract the number from the pattern

Hi
I have a file with the following entries:

Code:
cm2363db
cm2445db
cm2618db

Is there a awk or sed command which would allow me to extract only the numbers from this file as output, so the output would look like this:

Code:
2363
2445
2618


Thanks a lot -A

Last edited by vgersh99; 10-02-2009 at 02:03 PM.. Reason: code tags, PLEASE!
Bits Awarded / Charged to aoussenko for this Post
Date User Comment Amount
10-02-2009 vgersh99 added code tags - charged 5K bits -5,000
  #2 (permalink)  
Old 10-02-2009
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,131

Code:
echo 'cm2363db' | sed 's/[^0-9]//g'

  #3 (permalink)  
Old 10-02-2009
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,365

Code:
tr -cd '[[:digit:]]\n' < FILE

  #4 (permalink)  
Old 10-02-2009
anchal_khare anchal_khare is offline
Registered User
  
 

Join Date: Jun 2007
Location: Mumbai,India
Posts: 325
or with gnu grep:


Code:
grep -oE '[0-9]+' file

  #5 (permalink)  
Old 10-02-2009
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,365
Quote:
Originally Posted by anchal_khare View Post
or with gnu grep:


Code:
grep -oE '[0-9]+' file

That will put each set of numbers on a new line, not what the OP wants.
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 02:21 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0