From owner-freebsd-questions@FreeBSD.ORG Wed Mar 23 20:13:24 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 6737516A4CF for ; Wed, 23 Mar 2005 20:13:24 +0000 (GMT) Received: from mail.liquidation.com (mail.liquidation.com [65.196.108.169]) by mx1.FreeBSD.org (Postfix) with ESMTP id B102743D3F for ; Wed, 23 Mar 2005 20:13:23 +0000 (GMT) (envelope-from pgollucci@p6m7g8.com) Received: from [10.0.0.206] (everything.liquidation.com [65.196.108.171]) (authenticated bits=0) by mail.liquidation.com (8.12.9/8.12.9) with ESMTP id j2NKGaZT012380 (version=TLSv1/SSLv3 cipher=RC4-MD5 bits=128 verify=NO); Wed, 23 Mar 2005 15:16:42 -0500 Message-ID: <4241CEB4.4040909@p6m7g8.com> Date: Wed, 23 Mar 2005 15:16:52 -0500 From: "Philip M. Gollucci" Organization: Liquitidy Services, Inc. User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206) X-Accept-Language: en-us, en MIME-Version: 1.0 To: questions@freebsd.org References: <2635.209.87.176.4.1111607862.fusewebmail-19592@webmail.fusemail.com> In-Reply-To: <2635.209.87.176.4.1111607862.fusewebmail-19592@webmail.fusemail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-MailScanner-Information: Please contact the ISP for more information X-MailScanner: Found to be clean X-MailScanner-SpamCheck: not spam (whitelisted), SpamAssassin (score=-4.748, required 5, AWL 0.15, BAYES_00 -4.90) cc: brianjohn@fusemail.com 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 List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 23 Mar 2005 20:13:24 -0000 Brian John wrote: >>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 >_______________________________________________ >freebsd-questions@freebsd.org mailing list >http://lists.freebsd.org/mailman/listinfo/freebsd-questions >To unsubscribe, send any mail to "freebsd-questions-unsubscribe@freebsd.org" > > >I can see that the filenames not >starting with '00' will be piped, but what does the '\' do? The '\' means pretend I typed the next line on this line he used it because most mailers wrap the e-mail lines at 80 characters, but it needs to be on one line to work. If you wrote it on one line in the script file, you can omit that '\' Luck -- END ----------------------------------------------------------------------------- Philip M. Gollucci Senior Developer - Liquidity Services Inc. Phone: 202.568.6268 (Direct) E-Mail: pgollucci@liquidation.com Web: http://www.liquidation.com