#!sh grep and move files
mwm-dated-1049829134.52a521 at mired.org
Thu Apr 3 11:12:16 PST 2003
In <200304031147.30097.mbettinger at championelevators.com>, Matthew Bettinger <mbettinger at 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
> for x in `find /dir -type f -exec grep '1~TA'  \;`
> mv $x /newdir
Assuming there are few enough matching files that you don't run out of
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 Meyer <mwm at mired.org> http://www.mired.org/consulting.html
Independent Network/Unix/Perforce consultant, email for more information.
More information about the freebsd-questions