From owner-freebsd-questions Wed Feb 9 1:10:48 2000 Delivered-To: freebsd-questions@freebsd.org Received: from inet.chip-web.com (adsl-63-195-43-53.dsl.snfc21.pacbell.net [63.195.43.53]) by builder.freebsd.org (Postfix) with SMTP id B543E480D for ; Tue, 8 Feb 2000 19:15:26 -0800 (PST) Received: (qmail 22196 invoked from network); 9 Feb 2000 03:14:53 -0000 Received: from toy.chip-web.com (HELO bigfoot.com) (@172.16.1.30) by inet.chip-web.com with SMTP; 9 Feb 2000 03:14:53 -0000 Message-ID: <38A0DBAD.44AF1595@bigfoot.com> Date: Tue, 08 Feb 2000 19:14:53 -0800 From: Ludwig Pummer X-Mailer: Mozilla 4.7 [en] (X11; I; FreeBSD 3.4-STABLE i386) X-Accept-Language: en MIME-Version: 1.0 To: darryl@osborne-ind.com Cc: freebsd-questions@freebsd.org Subject: Re: OFF TOPIC - Shell Script Question References: <001101bf7273$e44dc250$070101c0@ruraltel.net> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG Darryl Hoar wrote: > > Greetings, > I have a directory with a ton of files in it. I need to move some of > them to another > directory. Here's what I'm thinking: > > ls -tl | grep '1999' | awk '{print "mv " $9 " /home/darryl/test"}' > > but it does not 'execute' the mv command. How do I get this cooking ? > > BTW, I don't plan on doing this a bunch, so I would preferr Not to > install, learn > perl. Instead, use the shell. If mv would let you invert the order of its arguments, an ls | awk | xargs | mv pipe would take care of this, but it doesn't so (I did this from tcsh): If the filenames actually have 1999 in them: ( echo '#\!/bin/sh' ; ls -tl | awk '/1999/ {print "mv " $9 " /home/darryl/test"}' ) > mvfile sh mvfile If the file's mtime is 199 and you don't care about what's in the filename: ( echo '#\!/bin/sh' ; ls -Ttl | awk '($9 == 1999) {print "mv " $10 " new"}' ) > mvfile sh mvfile Note that these will fail for files whose filenames contain spaces. --Ludwig Pummer To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message