What script would allow me to grep a keyword and print the filename containing the keyword inside the file content, for example 'Carhart' inside all .sas files in all subdirectories? I tried something like the following but it doesn't work:
(find . -name '*.sas' -prune -type f -exec grep 'Carhart' > /dev/tty) >& /dev/null
The script would satisfy two conditions
- It runs on tcsh on Solaris on SPARC-Enterprise, which is certified POSIX
- It does not generate 'Permission denied' lines on directories which I have no permission to search and/or read. ( find / -name '*.sas' -prune > /dev/tty ) > & /dev/null
Since ( find / -name '*.sas' -prune > /dev/tty ) > & /dev/null
works without reporting permission denied error, how can I modify this simple line to incorporate grep?
tcsh
is not and never will be certified to be POSIX compliant. On Solaris, you need to run/usr/xpg4/bin/sh
as your shell and have the POSIX PATH set to `getconf PATH) to comply.truss -a -f -u :: find /var ...
seems to confirm that it works like github.com/illumos/illumos-gate/blob/master/usr/src/cmd/find/… , that is, it callsnftw
and ifnftw
detects a directory that is not readable,find
outputs an error message before doing anything else (even before doing-type d -a test_for_unreadability -a -prune
) . The best thing to do may be to filter out the error messages on stderr rather than trying to come up with a set of conditions to pass tofind
that will make it avoid unreadable directories.open()
first. You will have them printed anyways. Is there a reason why you don't want them to be printed?