The time now is Sat 21 Apr 2018, 23:38
All times are UTC - 4 |
Author |
Message |
trio

Joined: 21 Dec 2008 Posts: 2083 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
_________________ My apps
|
Back to top
|
|
 |
dejan555

Joined: 30 Nov 2008 Posts: 2805 Location: Montenegro
|
Posted: Tue 09 Feb 2010, 09:18 Post subject:
|
|
you can use sed:
Code: | sed -n '9p' /path/to/file.txt |
_________________ puppy.b0x.me stuff mirrored HERE or HERE
|
Back to top
|
|
 |
seaside
Joined: 11 Apr 2007 Posts: 917
|
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: 103 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: 2083 Location: अनुमोदना
|
Posted: Wed 10 Feb 2010, 05:26 Post subject:
|
|
Thx all...seaside's answer did the job
_________________ My apps
|
Back to top
|
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|