Dan
Dan

Reputation: 378

Trouble with using grep to find a string in a text file

User enters in an email. I use grep to check if the email already exists within a specific file.

Here's the part of the code that I'm having trouble with

$word = [user input (email) ]
legit = [boolean that is used for something else. No problem with that here]

I'm new. Help me kindly please.

if [[ grep -f "$word" "/root/Desktop/Dan/Logs/member-name-file" "$variable.txt" ]]
            then
                echo "Email already exists on requested List**"
                legit=false
            else
                echo "Email added onto list**"
                legit=true
            fi

Upvotes: 1

Views: 130

Answers (1)

anubhava
anubhava

Reputation: 785146

Instead of:

if [[ grep -f "$word" "/root/Desktop/Dan/Logs/member-name-file" "$variable.txt" ]]

You can do:

if grep -q "$word" "/root/Desktop/Dan/Logs/member-name-file"

Upvotes: 1

Related Questions