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 > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
reverse an integer ali560045 Shell Programming and Scripting 4 05-20-2008 03:15 AM
get integer part ericaworld Shell Programming and Scripting 3 05-29-2007 03:16 PM
integer arrays primal High Level Programming 4 03-09-2002 05:40 PM
capturing the output of grep as integer variable babariba UNIX for Dummies Questions & Answers 2 11-16-2001 10:42 AM
How to get a rodom integer toddor High Level Programming 2 10-10-2001 07:21 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-31-2004
apalex apalex is offline
Registered User
  
 

Join Date: May 2001
Location: NY
Posts: 39
awk or grep for integer only

how do you print the lines that contain integers only, using grep or awk?

thanks ,
apalex

------------------
this file below:
qwerty
01234
asdfgh
01234
qwer12
asdf05

will be:
01234
01234
qwer12
asdf05
  #2 (permalink)  
Old 08-31-2004
google's Avatar
google google is offline Forum Advisor  
Moderator
  
 

Join Date: Jul 2002
Location: Atlanta
Posts: 740
you could use awk to get only those records that are integers only as you asked. However your example, you include records that are alphanumeric

awk ' /[[:digit:]]/ { print $0 } ' your_file
  #3 (permalink)  
Old 08-31-2004
apalex apalex is offline
Registered User
  
 

Join Date: May 2001
Location: NY
Posts: 39
you are right sorry about that.

how to awk, to print the lines with integers only, having random patterns.

from:

qwerty
12345
asdfg
56789
zxcvb
00001
58364
22222


will be:

12345
56789
00001
58364
22222
  #4 (permalink)  
Old 08-31-2004
apalex apalex is offline
Registered User
  
 

Join Date: May 2001
Location: NY
Posts: 39
can this be done using the same command above?

thanks.
apalex
  #5 (permalink)  
Old 08-31-2004
Ygor's Avatar
Ygor Ygor is offline Forum Staff  
Moderator
  
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,407
Try using grep...

grep -E '^[0-9]+$' file1
  #6 (permalink)  
Old 09-01-2004
google's Avatar
google google is offline Forum Advisor  
Moderator
  
 

Join Date: Jul 2002
Location: Atlanta
Posts: 740
Quote:
can this be done using the same command above?
Yes. You can use the Awk command above to produce a list of entries composed of only integers.

awk ' /[[:digit:]]/ { print $0 } ' your_file

from:

qwerty
12345
asdfg
56789
zxcvb
00001
58364
22222


will be:

12345
56789
00001
58364
22222
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 02:03 PM.


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