1

Right now I'm using ack to list all the files in a directory which contain a string literal. This outputs not only normal files but also special files called packages or bundles which are actually directories on OS X. That is fine except I'm piping that to another command that is expecting only true files. How do I exclude the packages and bundles but still include the files which match my search term inside those packages and bundles?

$ ack --literal --files-with-matches 'SearchTerm' 
Steve Moser
  • 7,647
  • 5
  • 55
  • 94
  • Are you reading the output line by line? If so try something like: `[ -f "$line" ] && `. -- Better yet use `find` from the beginning. – ShellFish Jul 06 '15 at 05:01
  • You should be able to filter them out by "file extension" on the `ack` command-line. Can you show your code? – cdarke Jul 06 '15 at 07:38
  • @cdarke I would like a generic solution. Maybe I could filter by UTI. Is there an easy way to script that? – Steve Moser Jul 06 '15 at 10:26

1 Answers1

1
  1. Even if you used a regex pattern to weed out files without a dot suffix, e.g. -G '.' , you'll end up missing those files without a suffix. In other words, I don't think you'll find a generic regex to filter files from non-files. That said...

  2. Perhaps there is a naming convention to your special files called packages or bundles? In which case, use ack's -G flag to filter them out (see the point above for an example).

  3. I'm guessing there is no way to tell these packages and bundles from other files, so I think you should resort to find . -type f -name and pipe the files to ack -- e.g:

    find <dir> -type f | ack --nofilter --literal --files-with-matches 'SearchTerm'

Community
  • 1
  • 1
gregory
  • 10,969
  • 2
  • 30
  • 42