The time now is Wed 19 Jun 2013, 04:12
All times are UTC - 4 |
| Author |
Message |
trio

Joined: 21 Dec 2008 Posts: 1786 Location: अनुमोदना
|
Posted: 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|My Website
|
|
Back to top
|
|
 |
dejan555

Joined: 30 Nov 2008 Posts: 2407 Location: Montenegro
|
Posted: Tue 09 Feb 2010, 09:18 Post_subject:
|
|
you can use sed:
| Code: | | sed -n '9p' /path/to/file.txt |
_________________

|
|
Back to top
|
|
 |
seaside
Joined: 11 Apr 2007 Posts: 841
|
Posted: 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
|
|
 |
Shel
Joined: 11 Apr 2009 Posts: 102 Location: Seattle, WA, USA, or Southern France
|
Posted: Wed 10 Feb 2010, 05:10 Post_subject:
|
|
If the number "9" is at the beginning of a line, you can check for that:
... of if it's followed with a space, you can check for that:
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
|
|
 |
trio

Joined: 21 Dec 2008 Posts: 1786 Location: अनुमोदना
|
Posted: Wed 10 Feb 2010, 05:26 Post_subject:
|
|
Thx all...seaside's answer did the job
_________________ PET Maker|WbarCC|My Website
|
|
Back to top
|
|
 |
|
|
|
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
|