Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Fri 24 Oct 2014, 17:36
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
grep an exact number
Post_new_topic   Reply_to_topic View_previous_topic :: View_next_topic
Page 1 of 1 Posts_count  
Author Message
trio


Joined: 21 Dec 2008
Posts: 1805
Location: अनुमोदना

PostPosted: Tue 09 Feb 2010, 08:52    Post_subject:  grep an exact number  

Dear all,

Please help this dummy, I want to grep an exact number, how to do that? And yes, I am stupid.

Example:
in a file you have lines numbered from 1 to 100, you want to grep exactly line number 9, but I do:

Code:
grep 9 /path/to/file.txt


I will get lines numbered 9, 19, 29, etc But I want only line number 9

Thanks

_________________
PET Maker|WbarCC
Back to top
View user's profile Send_private_message 
dejan555


Joined: 30 Nov 2008
Posts: 2687
Location: Montenegro

PostPosted: Tue 09 Feb 2010, 09:18    Post_subject:  

you can use sed:

Code:
sed -n '9p' /path/to/file.txt

_________________


Back to top
View user's profile Send_private_message Visit_website MSNM 
seaside

Joined: 11 Apr 2007
Posts: 887

PostPosted: Tue 09 Feb 2010, 12:21    Post_subject:  

Trio,

Also,

Code:
grep -w 9 /path/to/file.txt


The "-w" matches a single word only

s
Back to top
View user's profile Send_private_message 
Shel

Joined: 11 Apr 2009
Posts: 103
Location: Seattle, WA, USA, or Southern France

PostPosted: Wed 10 Feb 2010, 05:10    Post_subject:  

If the number "9" is at the beginning of a line, you can check for that:
Code:

grep '^9' filename

... of if it's followed with a space, you can check for that:
Code:

grep '9 ' filename

or combine the two, etc. grep will do fairly complex regular expressions, so you can look for a "9" at the beginning of a line, followed by, say, a capital letter:
Code:

grep '^9[A-Z]' filename

I think those are all correct, I'm not in a position to check them at the moment, but doco for grep is all over the 'net.

-Shel
Back to top
View user's profile Send_private_message 
trio


Joined: 21 Dec 2008
Posts: 1805
Location: अनुमोदना

PostPosted: Wed 10 Feb 2010, 05:26    Post_subject:  

Thx all...seaside's answer did the job
_________________
PET Maker|WbarCC
Back to top
View user's profile Send_private_message 
Display_posts:   Sort by:   
Page 1 of 1 Posts_count  
Post_new_topic   Reply_to_topic View_previous_topic :: View_next_topic
 Forum index » Off-Topic Area » Programming
Jump to:  

Rules_post_cannot
Rules_reply_cannot
Rules_edit_cannot
Rules_delete_cannot
Rules_vote_cannot
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0459s ][ Queries: 11 (0.0032s) ][ GZIP on ]