From owner-freebsd-questions@FreeBSD.ORG Thu Apr 3 11:15:20 2003 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 D2BED37B401 for ; Thu, 3 Apr 2003 11:15:20 -0800 (PST) Received: from osm.michaelines.net (osm.michaelines.net [66.238.77.213]) by mx1.FreeBSD.org (Postfix) with ESMTP id 4DF7F43F3F for ; Thu, 3 Apr 2003 11:15:20 -0800 (PST) (envelope-from jtrigg@spamcop.net) Received: by osm.michaelines.net (Postfix, from userid 1002) id 6BFE220D17; Thu, 3 Apr 2003 14:16:17 -0500 (EST) Date: Thu, 3 Apr 2003 14:16:17 -0500 From: Jim Trigg To: freebsd-questions@freebsd.org Message-ID: <20030403191617.GC58403@s-gabriel.org> Mail-Followup-To: freebsd-questions@freebsd.org References: <200304031147.30097.mbettinger@championelevators.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <200304031147.30097.mbettinger@championelevators.com> User-Agent: Mutt/1.4.1i X-Habeas-SWE-1: winter into spring X-Habeas-SWE-2: brightly anticipated X-Habeas-SWE-3: like Habeas SWE (tm) X-Habeas-SWE-4: Copyright 2002 Habeas (tm) X-Habeas-SWE-5: Sender Warranted Email (SWE) (tm). The sender of this X-Habeas-SWE-6: email in exchange for a license for this Habeas X-Habeas-SWE-7: warrant mark warrants that this is a Habeas Compliant X-Habeas-SWE-8: Message (HCM) and not spam. Please report use of this X-Habeas-SWE-9: mark in spam to . Subject: Re: #!sh grep and move files 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: Thu, 03 Apr 2003 19:15:21 -0000 On Thu, Apr 03, 2003 at 11:47:30AM -0600, Matthew Bettinger wrote: > > I am trying to find the best way to search through several thousand files and > move some to a different directory. The files are all prefixed with LB. > Like, LBX99.DAT141683. > > These are data transactions and contain one line. The lines i am trying to > search for all begin with > > 1~TA~ (standing for timeand attendance labor transactions) > > I've tried > > #!/usr/bin/sh > for x in `find /dir -type f -exec grep '1~TA' [] \;` This will print matching lines; what you want here is grep -l, but see below. > do > mv $x /newdir > done > ---------------------------- > > > There seems to be something i am missing like some output redirection or an > ls listing... probably alot more. > > I know this can be done in a one liner somehow but I need it to be executed > from cron. find is actually a bit of overkill; this can be done as follows: #!/usr/bin/sh mv `grep -lr '1~TA' /dir` /newdir If you're using it from cron, make sure to use full paths for mv and grep (and find, if you keep using it) as the cron path may not be what you expect. Jim -- Jim Trigg, Lord High Everything Else O- /"\ \ / ASCII RIBBON CAMPAIGN Hostmaster, Huie Kin family website X HELP CURE HTML MAIL Verger, All Saints Church - Sharon Chapel / \