Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

read a word from file and grep in other file

Status
Not open for further replies.

sumas

Programmer
Jul 9, 2006
9
US
Hello all,

I am trying to grep each word of a file.
I have a file with 1.txt,
rob
tom
john

I want to grep tom file.txt, grep rob file.txt,

I am struck at... I could do this awk '{print $1}' 1.txt | grep ??(not sure here)
Any help?
Thanks
 
Why not simply the -f option of the grep command ?
grep -f 1.txt file.txt

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Somehow both of them wont work. Not sure... If I am doing the right way.

 
For grep:
grep: illegal option -- f
Usage: grep -hblcnsviw pattern file . . .

For awk:
awk: syntax error near line 1
awk: bailing out near line 1
 
Hi

sumas said:
grep: illegal option -- f
In my reply to your same question in thread822-1254915 I mentioned that [tt]grep[/tt] with -f works with GNU [tt]grep[/tt]. Unix [tt]grep[/tt]s are abit different, but usually there are another [tt]grep[/tt] too, which is more compatible with the GNU version. Find it and run it with full path.

The same applies to the [tt]awk[/tt] solution and the GNU and Unix [tt]awk[/tt]s too. The other [tt]awk[/tt] usually could be runned as [tt]nawk[/tt] too.

Feherke.
 
I am using K shell in Sun workstation, if that helps!!
 
Feherke,

well it works with nawk.

thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top