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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Find first occurance of the word in a file

Status
Not open for further replies.

unirams

Programmer
Dec 25, 2001
20
IN
Hi,

Can anyone able to help me out in the following.

I want to find the first occurance of a word in a file. But I want to have that entire line (not that word alone).

Does grep has any options for that?

Regards,
Ram
 
Hello,

If I understand your needs, grep without any options should do the work. If you grep the file with the word you are looking for, the output will be all the lines containing that word:

%grep your_word file_name

If you only use the first line, then you have the first line containing the desired word:

%grep your_word your_file | head -n1

Does this satisfy your needs?

Bye,

jmiturbe
 
Here is an awk way to do that also:

awk '/WORD/{print;exit}' your_file

-jim
 
Hi jmiturbe, jmiturbe

In both ways its working fine. Thanks for your help.

Regards,
Ram
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top