Results 1 to 6 of 6

Thread: scripting - grep - distinct list of found files

  1. #1
    Join Date
    Jul 2014
    Beans
    335

    Question scripting - grep - distinct list of found files

    Hi all,
    When I look for some keyword1 in path1 and the keyword1 is found several times in the same file, it returns the file path several times accordingly.
    Is there any way to get distinct list of files (full file path) ?

  2. #2
    Join Date
    Apr 2012
    Beans
    7,256

    Re: scripting - grep - distinct list of found files

    What exactly is the command you are using? if you use grep's `-l` option it should exit after the first match:

    Code:
           -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.

  3. #3
    Join Date
    Aug 2013
    Beans
    73
    Distro
    Lubuntu

    Re: scripting - grep - distinct list of found files

    or even better:
    Code:
    ls -l /path1/*keyword1*
    Budgie and loving it.

  4. #4
    Join Date
    Jul 2014
    Beans
    335

    Re: scripting - grep - distinct list of found files

    steeldriver, aromo2,
    The -l option is exactly what I was looking for. Thanks!

  5. #5
    Join Date
    Apr 2012
    Beans
    7,256

    Re: scripting - grep - distinct list of found files

    ... fwiw I assumed you were searching for files with the keyword within their contents, not in their filenames

  6. #6
    Join Date
    Jul 2014
    Beans
    335

    Re: scripting - grep - distinct list of found files

    Yes, I was looking for a way to find file with keyword1 as part of file text, not part of filename. Anyway, ls -l would be helpful sometimes as well.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •