linux - I want to check if some given files contain more then 3 words from an input file in a shell script -
my first parameter file contains given words , rest other directories in i'm searching files, contain @ least 3 of words 1st parameter
i can print out number of matching words, when testing if it's greater 3 gives me error: test: many arguments
here's code:
#!/bin/bash file=$1 shift 1 in $* j in `find $i` if test -f "$j" if test grep -o -w "`cat $file`" $j | wc -w -ge 3 echo $j fi fi done done
you first need execute grep | wc, , compare output 3. need change if statement that. since using backquotes, cannot nest them, can use other syntax $(command), equivalent `command`:
if [ $(grep -o -w "`cat $file`" $j | wc -w) -ge 3 ] echo $j fi
Comments
Post a Comment