Date: Thu, 3 Apr 2003 13:12:13 -0600 From: Mike Meyer <mwm-dated-1049829134.52a521@mired.org> To: mbettinger@championelevators.com Cc: freebsd-questions@freebsd.org Subject: Re: #!sh grep and move files Message-ID: <16012.34701.619801.998489@guru.mired.org> In-Reply-To: <200304031147.30097.mbettinger@championelevators.com> References: <200304031147.30097.mbettinger@championelevators.com>
next in thread | previous in thread | raw e-mail | index | archive | help
In <200304031147.30097.mbettinger@championelevators.com>, Matthew Bettinger <mbettinger@championelevators.com> 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 <mike -- Mike Meyer <mwm@mired.org> http://www.mired.org/consulting.html Independent Network/Unix/Perforce consultant, email for more information.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?16012.34701.619801.998489>