From owner-freebsd-questions@FreeBSD.ORG Thu Apr 26 10:15:10 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 BC6AC16A401 for ; Thu, 26 Apr 2007 10:15:10 +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 972A813C45A for ; Thu, 26 Apr 2007 10:15:10 +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 l3QAFAaK006973 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 26 Apr 2007 03:15:10 -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 l3QAF9uX003468 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT) for ; Thu, 26 Apr 2007 03:15:09 -0700 Message-ID: <46307BB4.109@u.washington.edu> Date: Thu, 26 Apr 2007 03:15:16 -0700 From: Garrett Cooper User-Agent: Thunderbird 1.5.0.10 (Windows/20070221) MIME-Version: 1.0 CC: FreeBSD Mailing List References: <20070425072914.GA65634@thought.org> <462F0824.5000107@infracaninophile.co.uk> <20070425190042.GA70940@thought.org> In-Reply-To: <20070425190042.GA70940@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.25434 X-Uwash-Spam: Gauge=IIIIIII, Probability=7%, Report='__CP_URI_IN_BODY 0, __CT 0, __CTE 0, __CT_TEXT_PLAIN 0, __HAS_MSGID 0, __LINES_OF_YELLING 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:15:10 -0000 Gary Kline wrote: > On Wed, Apr 25, 2007 at 08:49:56AM +0100, Matthew Seaman wrote: >> -----BEGIN PGP SIGNED MESSAGE----- >> Hash: RIPEMD160 >> >> 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! >>> >> xargs(1) is your friend. >> >> Simply arrange for your awk script to print out the names of all the >> files you have selected to edit, then pipe the result into xargs. >> Like so: >> >> ls -l| awk '{if ($6 == "Apr" && $7 == 19 || $6 == "Mar" && $7 == 26 ) >> print $9}' | xargs vi > > > Doing a pipe thru "xargs vi" is the first thing that > failed--with: > > ex/vi: Vi's standard input and output must be a terminal > > > whereas > > ls -l| awk '{if ($6 == "Apr" && $7 == 19 || $6 == "Mar" && $7 > == 26 ) print $9}' > > > printed a slew of files to stdout. > >> This does assume that the file names you are using do not contain >> spaces, quote marks, brackets or other characters of syntactical >> significance to the shell. In that case you could use something like >> this: >> >> find . -type f \( -mtime 6 -o -mtime 29 \) -print0 | xargs -0 vi > > > No, no non-ASCII characters in the filenames. I'll try the -0 > and see if that gets rid of the "must be a terminal" blurb... > > > ph 11:47 [5133] ls -l| awk '{if ($6 == "Apr" && $7 == 19 || $6 == > "Mar" && $7 == 26 ) print $9}' | xargs -0 vi > ex/vi: Files with newlines in the name are unrecoverable > ex/vi: Modifications not recoverable if the session fails > ex/vi: Vi's standard input and output must be a terminal > > > Ah, so vi sees "filename\n" ... perhaps. [?] > > > > >> where find's '-print0' and the '-0' flag to xargs make the commands >> produce and consume respectively a null separated list of filenames. >> >> Unfortunately with find(1) there doesn't seem to be a way of expressing >> an absolute date / time -- all you can do is the time difference between >> now and when you want (which defaults to 'number of days' but can be set >> to use various other time units. I can think of a couple of ways of >> calculating that, but personally I'd find it cleaner to just roll the >> whole thing into a small perl script which identified the files in >> question and forked off an instance of vi(1) to do the editing. >> > > > You're probably right about the script. There are at least > dozens of files around ... they could be /bin/mv'd or cp'd to > a tmp and then run thru vi. --Or?? > > thanks much, Matthew. appreciate it, > > gary > > >> Cheers, >> >> Matthew >> >> - -- >> Dr Matthew J Seaman MA, D.Phil. Flat 3 >> 7 Priory Courtyard >> PGP: http://www.infracaninophile.co.uk/pgpkey Ramsgate >> Kent, CT11 9PW, UK >> -----BEGIN PGP SIGNATURE----- >> Version: GnuPG v2.0.3 (FreeBSD) >> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org >> >> iD8DBQFGLwgk3jDkPpsZ+VYRAxaaAJ9H4q3vD4qqBo+FijEs+PqmaR0kaQCgidpA >> kXOmJIpsODutFhLIvIoJpEE= >> =fNoc >> -----END PGP SIGNATURE----- > Or my favorite structure (bourne shell style).. for i in `ls -l | awk '{if ($6 == "Apr" && $7 == 19 || $6 == "Mar" && $7 == 26 ) print $9}'`; do vi $i; done Could you provide examples of what you are trying to edit though Gary? Thanks, -Garrett