Re: For Loop Question



Thanks, the 'while' works. I wasn't thinking of an option other than
'for' to process the file.

Sorry about the omission. I actually meant to include the $i in :
for i in `cat textfile`;do grep -i $i /etc/passwd; done

I do understand that I will still occasionally encounter multiple "John
Smith" occurances. It seem this is the best way to search until we have
all of our uids converted to match the corporate standard. But hey, at
least I won't be seeing 100 Smiths.

Thanks again.
Michael Tosch wrote:
newworldman@xxxxxxxxx wrote:
All,

I'm reading in a text file to a for loop to process against
/etc/passwd. Our password files have commetn fields that have firstname
lastname in them. We are provided a lsit of terminations with the names
not the uid.

I enter the names in a text file:
John Smith
Sally Q Public
etc.

I have a for loop:
for i in `cat textfile`;do grep -i /etc/passwd; done

-i
or
$i
?


The space between the first and lst name or middle initial is messing
up the for loop. It ends up searching for John not "John Smith" and
Sally not "Sally Q Public".

It appears that the space is treated as a delimiter and I have tried
various ways to escape it without success.

I'd apprecieat any ideas on how to proceed. Searching by just John or
just Smith gives too many irrelevant results.


Use a while loop instead and quote variables:

while read i
do
grep "$i" /etc/passwd
done < textfile


--
Michael Tosch @ hp : com

.



Relevant Pages

  • Re: For Loop Question
    ... I'm reading in a text file to a for loop to process against ... It ends up searching for John not "John Smith" and ...
    (comp.unix.questions)
  • For Loop Question
    ... I'm reading in a text file to a for loop to process against ... It ends up searching for John not "John Smith" and ...
    (comp.unix.questions)
  • Re: For Loop Question
    ... I'm reading in a text file to a for loop to process against ... It ends up searching for John not "John Smith" and ...
    (comp.unix.questions)
  • Re: Mail merge
    ... Assuming it's the same as in the PC environment, I'd have thought you could control the print paramters by setting up the paper source definitions in your mailmerge main document - before executing the merge. ... John, Smith, Jan, 10 ... > The merge involves a 2 page letter and pages for coupons. ...
    (microsoft.public.mac.office.excel)
  • Re: "Please tell me your name?"
    ... Smith being the family name and John the given name (= Christian ... They also often include grandparents' surnames as well: John Smith Jones Cooper Danks. ... I know someone who told me that he and his two brothers have three different surnames because they made different choices. ...
    (alt.usage.english)