-2

Using a script need to identify all files or folder which contains a specific keyword under given path. The path will have multiple folders. Below is the script that is used.

   #!/bin/sh
   DIR=''
   for FILE in ls "$DIR"*
   do
           # echo $FILE
               grep -l $FILE "*FY*"
    done
~
Biffen
  • 6,249
  • 6
  • 28
  • 36

1 Answers1

0

You have to give the "keyword" before the path to be searched. which it not the case in your script.

  grep -l -r "keyword" path/to/folder

Try the above script.

-l, --files-with-matches
          Suppress normal output; instead print the  name  of  each  input
          file  from  which  output would normally have been printed.  The
          scanning will stop on the first  match.   (-l  is  specified  by
          POSIX.)

-R, -r, --recursive
          Read all  files  under  each  directory,  recursively;  this  is
          equivalent to the -d recurse option.

for more info refer

Christina Jacob
  • 665
  • 5
  • 17