Curious G.
Curious G.

Reputation: 877

Checking a word in a file to do a statement by Shell

I have this file:

wwsex gender wwmm mother 
mm ccmother ccfather 

And I need to check if a file contains a specific word (exactly the same, identic) to do the statement considering just the second line. I tried this:

if grep -q ww 'my.file'; then
echo "correct - just a simple example" >> file
fi 

But it's wrong, this way I checked all the file and consider the wwsex and wwmm to do the statement. But I need to be specific in the word and the line.

Upvotes: 0

Views: 329

Answers (1)

KamilCuk
KamilCuk

Reputation: 141060

Use an option to grep that let's you select only lines containing matches that form full words: -w or --word-regex, see man grep.

if grep -wq ww 'my.file'; then

Upvotes: 1

Related Questions