Re: For Loop Question
- From: newworldman@xxxxxxxxx
- Date: 2 Jun 2006 08:20:09 -0700
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
.
- References:
- For Loop Question
- From: newworldman
- Re: For Loop Question
- From: Michael Tosch
- For Loop Question
- Prev by Date: Re: For Loop Question
- Next by Date: newbie - howto replace text from two files with sed?
- Previous by thread: Re: For Loop Question
- Next by thread: newbie - howto replace text from two files with sed?
- Index(es):
Relevant Pages
|