Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 26 Apr 2007 03:22:26 -0700
From:      Garrett Cooper <youshi10@u.washington.edu>
To:        FreeBSD Mailing List <freebsd-questions@freebsd.org>
Subject:   Re: first of misc questions....
Message-ID:  <46307D62.6030709@u.washington.edu>
In-Reply-To: <20070425191942.GB70940@thought.org>
References:  <20070425072914.GA65634@thought.org>	<6.0.0.22.2.20070425061655.0264d980@mail.computinginnovations.com> <20070425191942.GB70940@thought.org>

next in thread | previous in thread | raw e-mail | index | archive | help
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/<directory> 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 <what> "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/<foo> 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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?46307D62.6030709>