user2347191
user2347191

Reputation: 99

how to test if string does not exists in a file

I'm searching a file which should not have this string "section" using shell/perl.

Please help me to find way grep -vl command returns a file names if strings exists.

Upvotes: 1

Views: 15471

Answers (3)

Omer Dagan
Omer Dagan

Reputation: 15976

In perl:

    open(FILE,"<your file>");
    if (grep{/<your keyword>/} <FILE>){
       print "found\n";
    }else{
       print "word not found\n";
    }
    close FILE;

Upvotes: 4

drmrgd
drmrgd

Reputation: 733

A lot of times I'll do it this way:

for f in <your_files>; do grep -q "section" $f && echo $f || continue; done

That should print out a list of files that contain the word "section" in them.

Upvotes: -1

Rahul Tripathi
Rahul Tripathi

Reputation: 172458

You may try like this:-

grep -Fxq "$MYFILENAME" file.txt

or may be like this:-

if grep -q SearchString "$File"; then
   Do Some Actions
fi

Upvotes: 5

Related Questions