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!

how to find certain words in a file

Status
Not open for further replies.

mike73

Technical User
Aug 27, 2001
6
US
I am sorry, this questions seem too easy too someone in here but I am new in Linux so Please help.

what is the find command to find certain words in a file say for example: find a word {CHECKPOINT NOT COMPLETE} in a file name {ALERT.LOG}


something grep but I don't know the rest

Please help

thanks


 
#!/bin/sh

get_strings() {
_rget=$1

echo -n "String to look for: "
read str

grep -n $str $_rget

}

echo -n "File to search(full path please): "
read str
while test ! -z "$str"
do
get_strings $str
done

Awk is also very good at more specialized searches and
file manipulations as is sed.
 
Hi,

With grep you'd just do :

grep "CHECKPOINT NOT COMPLETE" alert.log

(assuming you were in the directory where the file was) or

grep -n "CHECKPOINT NOT COMPLETE" /var/log/alert.log

where you specify the full path and ask for the lines to be numbered, etc, etc.

Rgds

Rgds
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top