Re: for loop exclusion



In article <20060426201134.GA11552@xxxxxxxxxxxxxxxxxxx>,
Jeff Hyman <scolist@xxxxxxxxxx> wrote:
Hello all,

# for STRING in "jeff " <== Nope.
for STRING in jeff
do
grep -i $STRING ascii_file
done

In the above example,
how would one exclude "jeffrey" from being found
since I'm only looking for "jeff" ?

If you were just wondering why the above commented-out line didn't work, it's
because you didn't quote $STRING, and so lost the trailing space.

grep -i "$STRING" ascii_file

would not find jeffrey. But, it also wouldn't find "jeff" at the end of a
line. To search for 'jeff' as a word:

egrep -i '(^|[^[:alnum:]])jeff([^[:alnum:]]|$)'

This finds 'jeff' surrounded by non-alphanums or the ends of a line, equivalent
to the word-boundary operators available in some regular expression lexicons.

John
--
John DuBois spcecdt@xxxxxxxxxx KC6QKZ/AE http://www.armory.com/~spcecdt/
.



Relevant Pages

  • Re: Create Table SQL not working
    ... Tim & Jeff seemed to be so ... > concatenating the Number (converted to a string) to the end of a constant ...
    (microsoft.public.access.tablesdbdesign)
  • Trouble accessing db while using ASP.Net
    ... When I try to open the connection ... "Exception Message: ... ASP.LoginPage_aspx.CustomAuthenticate(String username, String ... User name: jeff" ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Make Multiple Tables via Query
    ... Dim strTableName As String ... Dim strExcelFileName As String ... "Jeff Boyce" wrote: ...
    (microsoft.public.access.queries)
  • Re: GAS
    ... What did you play, Jeff? ... rosewood at a used price that has almost everything I'd been selling myself ... I'd been working myself up to a $1.5k to $2k nice OM or similar six string ...
    (rec.music.makers.guitar.acoustic)
  • Re: Standard FileOpen Window
    ... "Jeff Jones" wrote in message ... > Private Type OPENFILENAME ... > lpstrCustomFilter As String ... > FileName = Trim$ ...
    (microsoft.public.project.vba)