From owner-freebsd-questions@FreeBSD.ORG Thu Apr 26 10:22:20 2007 Return-Path: X-Original-To: freebsd-questions@freebsd.org Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id BB62A16A40F for ; Thu, 26 Apr 2007 10:22:20 +0000 (UTC) (envelope-from youshi10@u.washington.edu) Received: from mxout5.cac.washington.edu (mxout5.cac.washington.edu [140.142.32.135]) by mx1.freebsd.org (Postfix) with ESMTP id 9690B13C4B7 for ; Thu, 26 Apr 2007 10:22:20 +0000 (UTC) (envelope-from youshi10@u.washington.edu) Received: from smtp.washington.edu (smtp.washington.edu [140.142.33.9] (may be forged)) by mxout5.cac.washington.edu (8.13.7+UW06.06/8.13.7+UW07.03) with ESMTP id l3QAMJ5Y008253 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 26 Apr 2007 03:22:20 -0700 X-Auth-Received: from [192.168.100.45] (c-67-161-171-107.hsd1.ca.comcast.net [67.161.171.107]) (authenticated authid=youshi10) by smtp.washington.edu (8.13.7+UW06.06/8.13.7+UW07.03) with ESMTP id l3QAMJO5003780 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT) for ; Thu, 26 Apr 2007 03:22:19 -0700 Message-ID: <46307D62.6030709@u.washington.edu> Date: Thu, 26 Apr 2007 03:22:26 -0700 From: Garrett Cooper User-Agent: Thunderbird 1.5.0.10 (Windows/20070221) MIME-Version: 1.0 To: FreeBSD Mailing List References: <20070425072914.GA65634@thought.org> <6.0.0.22.2.20070425061655.0264d980@mail.computinginnovations.com> <20070425191942.GB70940@thought.org> In-Reply-To: <20070425191942.GB70940@thought.org> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-PMX-Version: 5.3.1.294258, Antispam-Engine: 2.5.1.298604, Antispam-Data: 2007.4.26.30434 X-Uwash-Spam: Gauge=IIIIIII, Probability=7%, Report='__CT 0, __CTE 0, __CT_TEXT_PLAIN 0, __HAS_MSGID 0, __MIME_TEXT_ONLY 0, __MIME_VERSION 0, __SANE_MSGID 0, __STOCK_PHRASE_7 0, __USER_AGENT 0' Subject: Re: first of misc questions.... X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 26 Apr 2007 10:22:20 -0000 Gary Kline wrote: > On Wed, Apr 25, 2007 at 06:21:52AM -0500, Derek Ragona wrote: >> At 02:29 AM 4/25/2007, Gary Kline wrote: >>> Guys, >>> >>> This is an awk-type question. Hopefully a one-liner. If I >>> need to use #!/usr/bin/awk and a BEGIN/END (or whatever it is), >>> that's okay... >>> >>> I want to do an ls -l in a /home/kline/ and find and >>> edit files that are dated (let's say) Apr 19 or Mar 26. This >>> works to print $9 the filenames. >>> >>> ls -l| awk '{if ($6 == "Apr" && $7 == 19 || $6 == "Mar" && $7 >>> == 26 ) print $9}' >>> >>> What's the final part to get awk to vi $9? Or another pipe and >>> xargs and "vi"? Nothing simple works, so thanks for any >>> clues! >> I would use a simple approach incase you need to re-edit the list since >> editing will change file times: >> ls -l| awk '{if ($6 == "Apr" && $7 == 19 || $6 == "Mar" && $7 == 26 ) >> print $9}' > /tmp/myfilelist >> then you can: >> for i in `cat /tmp/myfilelist`;do vi $i;done >> >> if you don't want to use a file, you can do in one shell loop too, but >> again this will change your file modification times: >> for i in `ls -l| awk '{if ($6 == "Apr" && $7 == 19 || $6 == "Mar" && $7 == >> 26 ) print $9}'`;do vi $i;done > > > Yep; this is the simple kind of script I had in mind first but > wasn't sure if/how it would work. Your one-liner works > "as-advertized", but then as you note, the timestamp is > changed!! (duh)... So it does make more sense to put the list > into a /tmp/ file. Save typing when I re-edit. > > thanks much, indeed, > > gary > > >> -Derek Don't forget my friendly, friend cut(1) (almost forgot that in my previous post). I think it's a lot more lightweight and faster than awk is; the only drawback is that delimiters are only 1 character wide, whereas heavier weight text processing tools can do multiple character search and replacements (sed, awk, perl, etc). ls -l | cut -d ' ' -f 9 | xargs vi {} \; # change -f to meet your needs -Garrett