![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Grep help | flood | Shell Programming and Scripting | 3 | 06-05-2008 10:14 PM |
| Grep | Aejaz | UNIX for Advanced & Expert Users | 3 | 04-30-2008 04:10 AM |
| grep | dineshr85 | Shell Programming and Scripting | 1 | 10-10-2007 01:52 AM |
| how to exclude the GREP command from GREP | yamsin789 | UNIX for Advanced & Expert Users | 2 | 10-04-2007 11:59 PM |
| Make grep -c display like grep -n? | Jerrad | Shell Programming and Scripting | 2 | 08-24-2006 09:20 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
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!. |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
that should work,
Code:
>cat a 1 2 11 12 1 Code:
>i=1 >grep -w $i a 1 1 |
|
#3
|
|||
|
|||
|
hi,
thanks for the reply. the problem is because i'm using cat -n to number the lines in the file and then try to grep the line number. cat -n puts whitespace and i think that's where i 'm going wrong. the format is 1 name 2 name 3 name . n name thanks |
|
#4
|
|||
|
|||
|
pointer !
Code:
cat a 1 name 2 name 3 name . n name Code:
i=1 sed -n "/$i/p" a | sed 's/ .*$//' |
|
#5
|
|||
|
|||
|
Code:
awk '/1/{
for (i=1;i<=NF;i++){
if ( $i == "1"){
print
}
} } ' "file"
|
|||
| Google The UNIX and Linux Forums |
| Thread Tools | |
| Display Modes | |
|
|