Computing.Net > Forums > Unix > Search for words in a text file

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Search for words in a text file

Reply to Message Icon

Name: Mitesh
Date: September 17, 2007 at 04:09:15 Pacific
OS: Unix
CPU/Ram: Intel, 512MB
Product: Dell
Comment:

Hi,
I am a unix newbie.

I am trying the following to search for a number of words in a text file (@unix command prompt), but the entire file contents are displayed. Can anyone tell me where I am making a mistake? Thanks Mitesh

for i in `cat /tmp/mylist`
> do
> grep i /etc/passwd
> done

mylist contains Users names.

Thanks
Mitesh




Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: September 17, 2007 at 07:24:39 Pacific
Reply:

#!/bin/ksh

# untested as I'm not near a unix box and
# I'm assuming there's one word per line

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


0

Response Number 2
Name: Mitesh
Date: September 19, 2007 at 01:54:02 Pacific
Reply:

Ah silly me, I was forgetting to add the '$' sign before the variable.. It now works. Thanks mate!

Mitesh


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Search for words in a text file

How to detect EOF of a text file www.computing.net/answers/unix/how-to-detect-eof-of-a-text-file/5111.html

Converting PCL to a text file www.computing.net/answers/unix/converting-pcl-to-a-text-file/5050.html

Parsing and emailing a text file www.computing.net/answers/unix/parsing-and-emailing-a-text-file-/6623.html