Reputation: 99
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
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
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
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