From owner-freebsd-questions@FreeBSD.ORG Wed Mar 23 19:57:51 2005 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 8B61B16A4CE for ; Wed, 23 Mar 2005 19:57:51 +0000 (GMT) Received: from smtp-gw2.fusemail.net (smtp-gw2.fusemail.net [65.61.162.171]) by mx1.FreeBSD.org (Postfix) with ESMTP id E650643D1D for ; Wed, 23 Mar 2005 19:57:50 +0000 (GMT) (envelope-from brianjohn@fusemail.com) Received: from fusemail.com by smtp-gw2.fusemail.net with esmtp (FuseMail extSMTP) id 1DEByL-0002u9-UU for freebsd-questions@freebsd.org; Wed, 23 Mar 2005 14:56:58 -0500 Received: from fusemail.com by fuse1.fusemail.net with asmtp (FuseMail extSMTP) id 1DEByu-0006ou-IZ; Wed, 23 Mar 2005 13:57:32 -0600 Received: from 209.87.176.4 (FuseMail web AccountID 19592) by webmail.fusemail.com with HTTP; Wed, 23 Mar 2005 13:57:42 -0600 (CST) Message-ID: <2635.209.87.176.4.1111607862.fusewebmail-19592@webmail.fusemail.com> Date: Wed, 23 Mar 2005 13:57:42 -0600 (CST) From: "Brian John" To: "Giorgos Keramidas" , freebsd-questions@freebsd.org User-Agent: FuseMail W MIME-Version: 1.0 Content-Type: text/plain;charset=iso-8859-1 Subject: Re: Simple bash script to grep files for bad keywords X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: brianjohn@fusemail.com List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 23 Mar 2005 19:57:51 -0000 > On 2005-03-23 12:29, Brian John 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