From owner-freebsd-questions@FreeBSD.ORG Thu Apr 3 11:12:16 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 7D6F537B401 for ; Thu, 3 Apr 2003 11:12:16 -0800 (PST) Received: from mired.org (ip68-97-54-220.ok.ok.cox.net [68.97.54.220]) by mx1.FreeBSD.org (Postfix) with SMTP id 48AC543FB1 for ; Thu, 3 Apr 2003 11:12:15 -0800 (PST) (envelope-from mwm-dated-1049829134.52a521@mired.org) Received: (qmail 83586 invoked from network); 3 Apr 2003 19:12:14 -0000 Received: from localhost.mired.org (HELO guru.mired.org) (127.0.0.1) by localhost.mired.org with SMTP; 3 Apr 2003 19:12:14 -0000 Received: by guru.mired.org (tmda-inject, from uid 100); Thu, 03 Apr 2003 13:12:14 -0600 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <16012.34701.619801.998489@guru.mired.org> Date: Thu, 3 Apr 2003 13:12:13 -0600 To: mbettinger@championelevators.com In-Reply-To: <200304031147.30097.mbettinger@championelevators.com> References: <200304031147.30097.mbettinger@championelevators.com> X-Mailer: VM 7.07 under 21.1 (patch 14) "Cuyahoga Valley" XEmacs Lucid X-face: "5Mnwy%?j>IIV\)A=):rjWL~NB2aH[}Yq8Z=u~vJ`"(,&SiLvbbz2W`; h9L,Yg`+vb1>RG% *h+%X^n0EZd>TM8_IB;a8F?(Fb"lw'IgCoyM.[Lg#r\ From: Mike Meyer X-Delivery-Agent: TMDA/0.73 (Jet Pilot) cc: freebsd-questions@freebsd.org 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:12:16 -0000 In <200304031147.30097.mbettinger@championelevators.com>, Matthew Bettinger typed: > 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. > 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' [] \;` > do > mv $x /newdir > done Assuming there are few enough matching files that you don't run out of arguments, try: cd /dir; mv $(grep -lr 1-TA- .) /newdir will do the trick. If you have to man files for arguments, then you can use xargs: $ cd /dir $ grep -lr 1-TA- . | xargs -J % mv % /newdir http://www.mired.org/consulting.html Independent Network/Unix/Perforce consultant, email for more information.