The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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
extract numbers from a word systemali Shell Programming and Scripting 14 03-30-2009 03:47 AM
Extract numbers from a string and store in variables davewg Shell Programming and Scripting 6 11-14-2007 05:22 AM
grep for non numbers shihabvk Shell Programming and Scripting 6 09-20-2005 09:06 PM
grep numbers range azmathshaikh Shell Programming and Scripting 1 08-08-2005 07:45 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-30-2007
baghera baghera is offline
Registered User
  
 

Join Date: Aug 2007
Posts: 23
grep or awk problem, unable to extract numbers

Hi, I've trouble getting some numbers from a html-file. The thing is that I have several html-logs that contains lines like this:

nerdnerd, how_old_r_u:45782<br>APPLY: <hour_second> Verification succeded

This is some of what I've extracted from a html file but all I really want is the number in the middle. When using awk I get:


how_old_r_u:45782<br>APPLY:

since there is a space at each end, like a separator for awk.

And I tried using grep "[0-9]" but it only takes the whole line containing the number so I get the whole line again. Is there any command that can retreive the numbers only?
  #2 (permalink)  
Old 08-30-2007
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,796
The pattern is not very clear. But you can try

Code:
grep -oE "[[:digit:]]{1,}" input.txt
If that does not satisfy your requirement, perhaps this.

Code:
sed -n -e "s/.*:\([0-9]*\).*/\1/p" input.txt
  #3 (permalink)  
Old 08-31-2007
baghera baghera is offline
Registered User
  
 

Join Date: Aug 2007
Posts: 23
Quote:
Originally Posted by vino View Post
The pattern is not very clear. But you can try

Code:
grep -oE "[[:digit:]]{1,}" input.txt
If that does not satisfy your requirement, perhaps this.

Code:
sed -n -e "s/.*:\([0-9]*\).*/\1/p" input.txt
But if there is more numbers on that line for example:

how_old_r_u:45782<br>APPLY:[30000,t3,t4]:Plummet

It seems when I run the command

Code:
grep -oE "[[:digit:]]{1,}" input.txt
I also get the other numbers is there some way to get only 45782?
  #4 (permalink)  
Old 08-31-2007
fazliturk fazliturk is offline
Registered User
  
 

Join Date: Aug 2007
Posts: 45
cut -f2 -d: inputfile |sed s/[^0-9]//g
  #5 (permalink)  
Old 08-31-2007
charbel charbel is offline
Registered User
  
 

Join Date: Feb 2006
Posts: 41
Is that number composed of 5 digits only?
if YES, then you can use the awk command and you can print that substring only....

code:
cat input.txt|awk 'BEGIN {FS=":"} {print substr($2,1,5)}'

this may help.....
  #6 (permalink)  
Old 08-31-2007
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,425
Quote:
Originally Posted by charbel View Post
Is that number composed of 5 digits only?
if YES, then you can use the awk command and you can print that substring only....

code:
cat input.txt|awk 'BEGIN {FS=":"} {print substr($2,1,5)}'

this may help.....
no need for cat.
Code:
awk 'BEGIN {FS=":"} {print substr($2,1,5)}' input.txt
  #7 (permalink)  
Old 08-31-2007
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,796
Quote:
Originally Posted by baghera View Post
But if there is more numbers on that line for example:

how_old_r_u:45782<br>APPLY:[30000,t3,t4]:Plummet

It seems when I run the command

Code:
grep -oE "[[:digit:]]{1,}" input.txt
I also get the other numbers is there some way to get only 45782?
Which is why the sed alternative was provided. Did you try that ? Does that give you what you are looking for ?
Sponsored Links
Closed Thread

Bookmarks

Tags
grep or

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 09:27 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
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