LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-03-2005, 09:41 PM   #1
saiz66
Member
 
Registered: Apr 2003
Posts: 225

Rep: Reputation: 30
using grep help


How do I get grep to return to me the lines that ONLY contain digits? Thanks!
 
Old 02-03-2005, 09:52 PM   #2
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 61
Try this...
grep -o "[0-9]*"
 
Old 02-03-2005, 09:57 PM   #3
saiz66
Member
 
Registered: Apr 2003
Posts: 225

Original Poster
Rep: Reputation: 30
thanks but i have a file with a line of 12abc and I am supposed to only get the lines which have ONLY digits which in that case i shouldnt receive anything back from grep.. but when I run your code I get 12... which is not what I want..
 
Old 02-03-2005, 09:58 PM   #4
jtshaw
Senior Member
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 67
You'd want to use the regular expression syntax for that.

Something like: grep --regex="[1-9*]" <file>

There are a bunch of sites that will give you indepth information on regular expressions.

The Regular Expression Tutorial and this Regular Expression How-To might be helpful, though neither deals specifically with grep.
 
Old 02-03-2005, 10:50 PM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,358

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
This is along the right lines...
grep [0-9] file|grep -v [a-zA-z]

I'm assuming this isn't a homework qn?
http://www.catb.org/~esr/faqs/smart-....html#homework
 
Old 02-03-2005, 10:56 PM   #6
jtshaw
Senior Member
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 67
Ya, sorry, I was refreshing my grep usage before I posted and didn't notice that somebody had already posted the same thing... and that you had already said it wasn't quite what you were looking for
 
  


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
grep ?? can grep us variables? DaFrEQ Linux - Software 4 09-14-2005 12:22 PM
about grep ringerxyz Programming 1 03-03-2005 01:52 AM
What does rpm -qa |grep th* (as compared to rpm -qa |grep th) display? davidas Linux - Newbie 2 03-18-2004 01:35 AM
"Undeleting" data using grep, but get "grep: memory exhausted" error SammyK Linux - Software 2 03-13-2004 03:11 PM
ps -ef|grep -v root|grep apache<<result maelstrombob Linux - Newbie 1 09-24-2003 11:38 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:38 AM.

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