The UNIX Forums
"Join the Network of UNIX System Users"


 
britishguy
Newbie
Rank: 1



UID 77
Digest Posts 0
Credits 0
Posts 71
Reading Access 10
Registered Apr 25, 2007
Status Offline
Post at Jun 20, 2007 10:29 AM  Profile | P.M. 
help with grep



help with grep



hi.

i'm trying to grep a line that starts with a specific number from a file using a loop. the problem is:

grep -w $i filename (e.g. for i=1)

gives me back

line 1
line 10
line 11
...
and so forth. i only want 1 (and not 11, 12, 13. and so forth).

i need a loop that goes up to a large value, so i don't want to restrict the number of characters i'm searching for. i just want to match whole words and not letters within words. i thought the -w flag did that, but it's not. i also tried grep \<1\> to search for just "1" but i get no results back.


thanks for your help!.


Top
asterix
Newbie
Rank: 1



UID 60
Digest Posts 0
Credits 0
Posts 49
Reading Access 10
Registered Apr 25, 2007
Status Offline
Post at Jun 20, 2007 10:29 AM  Profile | P.M. 
that should work,


code:
>cat a
1
2
11
12
1


code:
>i=1
>grep -w $i a
1
1
Top
 

 

All times are GMT, the time now is Mar 15, 2010 03:46 PM

Powered by Discuz! 5.0.0  © 2001-2006 UNIX Forums
Processed in 0.004898 second(s), 8 queries

Clear Cookies - Contact Us - UNIX Help - Archiver - WAP