Date: Wed, 23 Mar 2005 13:57:42 -0600 (CST) From: "Brian John" <brianjohn@fusemail.com> To: "Giorgos Keramidas" <keramida@ceid.upatras.gr>, freebsd-questions@freebsd.org Subject: Re: Simple bash script to grep files for bad keywords Message-ID: <2635.209.87.176.4.1111607862.fusewebmail-19592@webmail.fusemail.com>
next in thread | raw e-mail | index | archive | help
> On 2005-03-23 12:29, Brian John <brianjohn@fusemail.com> wrote: > > Hello, > > I am trying to write a simple bash script that will grep all files > > in a directory (except ones that start with "00") for certain bad > > keywords. Here is what I have so far: > > > #!/bin/bash > > > > # This is a simple script to check all sql scripts for bad keywords > > > > BAD_KEYWORDS='spool echo timing commit rollback' > > > > for i in $BAD_KEYWORDS; > > do > > echo "*********************************"; > > echo "GREPing for bad keyword '$i'" > > echo "*********************************"; > > grep $i ./*; > > done > > > > However, I'm not sure how to make it not grep the files that start > > with "00". Can anyone help me with this? > > Use xargs, since it will buy you the extra feature of being able to > search through arbitrarily large numbers of files: > > for _word in ${BAD_KEYWORDS} ;do > find . | grep -v '^/00' |\ > xargs grep "${_word}" /dev/null > done > > Tips: > > - The quotes in "${_word}" are probably optional, but it's better to > be safe than sorry :-) > > - The /dev/null is there so that grep will get at least 2 file > arguments, even if there is just one file in the current directory, > effectively forcing grep(1) to print the filename of this one file > if it happens to match the pattern. > Cool, I think I get it for the most part. However, what exactly am I doing when I am piping to xargs? I can see that the filenames not starting with '00' will be piped, but what does the '\' do? Sorry, I am really new to scripting and *nix in general. But I am a programmer so I learn fast. Thanks! /Brian
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi? <2635.209.87.176.4.1111607862.fusewebmail-19592>