Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Print Filenames where keyword is missing 2

Status
Not open for further replies.

gsgb1

Programmer
Jul 31, 2004
21
CA
I have over 100 shell files in a directory and some of them do not have mandatory keyword in code like "Author" in there.

How do I find file names where specific keyword is not existing in any of the scripts in folder?

Example given below was used to find filenames when Keyword existed. Any way to fix this one so I get filename wherever keyword does not exist?

Code:
find . -name "*.sh" -exec grep -e "Author" {} /dev/null \;

Thanks.

GSGB
 
Try this...
Code:
find . -name '*.sh' ! -exec /usr/xpg4/bin/grep \-q 'Author' {} \; -print
This was done on Solaris where the "[tt]-q[/tt]" option is only in the "xpg4" version of [tt]grep[/tt]. If your [tt]grep[/tt] supports a quiet mode, then you don't need the full path on the [tt]grep[/tt].

Hope this helps.
 
I am using AIX 5, and I get this error

find: 0652-083 Cannot execute /usr/xpg4/bin/grep:: A file or directory in the path name does not exist.[/color red]
 
It is working, I just removed /usr/xpg4/bin from command.

Thanks a lot for your help.
 
Yeah. Solaris has two [tt]grep[/tt]s. One supports the "[tt]-q[/tt]", the other doesn't.

Glad it's working for you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top