Re: first of misc questions....

2007-04-26 Thread Gary Kline
On Thu, Apr 26, 2007 at 03:15:16AM -0700, Garrett Cooper wrote:
> Gary Kline wrote:

[[ ... ]]

> 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?


There are a whole slew of html/php files (from jottings.thought.org) 
that I've been [[ koff, koff ]] meaning to edit and fine-tune.  This
for about a year.  "jOttings" are my personal meditations that
have been online for years.  They'll always be online, but it's 
a wee bit hard to cuddle up and read stuff on one's computer.
Even a laptop, right?  So, long-story-short, I've been trying to
get these mumblings into ink+paper.  So they've got to be
readable.   "Perfect" is impossible; so maybe *polished*.

Turns out that your and Derek Ragona's /bin/sh + awk is what I'm
using.  (OT, but the 30-45 files I'm editing had some bloopers;
misspellings, puncutation errs, and more.  So the files are in
/tmp/Jot. [!] )

gary

> 
> Thanks,
> -Garrett
> ___
> freebsd-questions@freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-questions
> To unsubscribe, send any mail to "[EMAIL PROTECTED]"

-- 
  Gary Kline  [EMAIL PROTECTED]   www.thought.org  Public Service Unix

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: first of misc questions....

2007-04-26 Thread Garrett Cooper

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
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: first of misc questions....

2007-04-26 Thread Garrett Cooper

Matthew Seaman wrote:

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA256

Irsla wrote:

Hi,

On 4/25/07, Matthew Seaman <[EMAIL PROTECTED]> wrote:

   find . -type f \( -mtime 6 -o -mtime 29 \) -print0 | xargs -0 vi


what about the -exec option of find ? I always wonder why people don't
use it.

find . -type f \( -mtime 6 -o -mtime 29 \) -exec vi {} \;



The critical difference is that 'find | xargs foo' runs foo once[*],
to process all the files in one go. 'find -exec foo {}' runs foo one
time for  each matched file.  In this case, it's probably not a big
deal, but  when you need to process hundreds of files 'find | xargs
foo' is much more efficient.

Cheers,

Matthew

[*] Actually, it runs foo repeatedly with as many filenames on the
foo command line as it can each time.  That's generally several
hundred files at a go.

- --
Dr Matthew J Seaman MA, D.Phil.   7 Priory Courtyard
  Flat 3
PGP: http://www.infracaninophile.co.uk/pgpkey Ramsgate
  Kent, CT11 9PW
-BEGIN PGP SIGNATURE-
Version: GnuPG v2.0.3 (FreeBSD)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGMEdC8Mjk52CukIwRCC97AJwPY6m5uHCQ/AvdnyjceQZDDtvmngCgi0RV
Im64VTob1mZRGtczhMIAaRQ=
=RaJi
-END PGP SIGNATURE-


Doesn't -xargs prebuffer input via xargs, where -exec does exec on the fly?
-Garrett
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: first of misc questions....

2007-04-26 Thread Garrett Cooper

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
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: first of misc questions....

2007-04-25 Thread Matthew Seaman
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA256

Irsla wrote:
> Hi,
> 
> On 4/25/07, Matthew Seaman <[EMAIL PROTECTED]> wrote:
>>
>>find . -type f \( -mtime 6 -o -mtime 29 \) -print0 | xargs -0 vi
>>
> 
> what about the -exec option of find ? I always wonder why people don't
> use it.
> 
> find . -type f \( -mtime 6 -o -mtime 29 \) -exec vi {} \;
> 

The critical difference is that 'find | xargs foo' runs foo once[*],
to process all the files in one go. 'find -exec foo {}' runs foo one
time for  each matched file.  In this case, it's probably not a big
deal, but  when you need to process hundreds of files 'find | xargs
foo' is much more efficient.

Cheers,

Matthew

[*] Actually, it runs foo repeatedly with as many filenames on the
foo command line as it can each time.  That's generally several
hundred files at a go.

- --
Dr Matthew J Seaman MA, D.Phil.   7 Priory Courtyard
  Flat 3
PGP: http://www.infracaninophile.co.uk/pgpkey Ramsgate
  Kent, CT11 9PW
-BEGIN PGP SIGNATURE-
Version: GnuPG v2.0.3 (FreeBSD)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGMEdC8Mjk52CukIwRCC97AJwPY6m5uHCQ/AvdnyjceQZDDtvmngCgi0RV
Im64VTob1mZRGtczhMIAaRQ=
=RaJi
-END PGP SIGNATURE-
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: first of misc questions....

2007-04-25 Thread RW
On Wed, 25 Apr 2007 14:53:26 -0700
Bill Campbell <[EMAIL PROTECTED]> wrote:

> On Wed, Apr 25, 2007, Thomas Dickey wrote:
> >On Wed, Apr 25, 2007 at 10:31:45PM +0200, Irsla wrote:
> >> On 4/25/07, Matthew Seaman <[EMAIL PROTECTED]> wrote:
> >> >
> >> >   find . -type f \( -mtime 6 -o -mtime 29 \) -print0 | xargs -0
> >> > vi
> >> >
> >> 
> >> what about the -exec option of find ? I always wonder why people
> >> don't use it.
> >
> >it's simpler but not necessarily as efficient.
> 
> How could it be as efficient as it executes the -exec for every thing
> that find finds? Xargs groups the output (except under rare
> circumstances where one might specify that it run the command for
> each argument).

This is one of those things that isn't actually true, but has been
repeated so many times that people have come to believe it. The -exec
option can be made to pass multiple arguments if it's used correctly.
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: first of misc questions....

2007-04-25 Thread Gary Kline
On Wed, Apr 25, 2007 at 10:31:45PM +0200, Irsla wrote:
> Hi,
> 
> On 4/25/07, Matthew Seaman <[EMAIL PROTECTED]> wrote:
> >
> >   find . -type f \( -mtime 6 -o -mtime 29 \) -print0 | xargs -0 vi
> >
> 
> what about the -exec option of find ? I always wonder why people don't use 
> it.
> 
> find . -type f \( -mtime 6 -o -mtime 29 \) -exec vi {} \;
> 
> '{}" <= is the filename find found
> you need a ';" to tell find that the command stops here (in case you
> want to add more options to find) and the '\" is mandatory eitherwise
> your SHELL will interfear.
> 
> btw don't forget the space between the '{}" and the '\;"
> 

Thanks, but I've known this "-exec foo {} \;" for several 
years.  I found it on this -questions list that is about as 
savvy a list as exists!  Thw -mtime N -o -mtime M stuff is
uncommon enough, tho, to not be in my bag of tricks.

:-)

gary


> 
> Regards,
> 
> -- 
> A: Maybe because some people are too annoyed by top-posting.
> Q: Why do I not get an answer to my question(s)?
> A: Because it messes up the order in which people normally read text.
> Q: Why is top-posting such a bad thing?
> 
> WAKIM Robert
> ___
> freebsd-questions@freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-questions
> To unsubscribe, send any mail to "[EMAIL PROTECTED]"

-- 
  Gary Kline  [EMAIL PROTECTED]   www.thought.org  Public Service Unix

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: first of misc questions....

2007-04-25 Thread Bill Campbell
On Wed, Apr 25, 2007, Thomas Dickey wrote:
>On Wed, Apr 25, 2007 at 10:31:45PM +0200, Irsla wrote:
>> On 4/25/07, Matthew Seaman <[EMAIL PROTECTED]> wrote:
>> >
>> >   find . -type f \( -mtime 6 -o -mtime 29 \) -print0 | xargs -0 vi
>> >
>> 
>> what about the -exec option of find ? I always wonder why people don't use 
>> it.
>
>it's simpler but not necessarily as efficient.

How could it be as efficient as it executes the -exec for every thing that
find finds? Xargs groups the output (except under rare circumstances where
one might specify that it run the command for each argument).

Bill
--
INTERNET:   [EMAIL PROTECTED]  Bill Campbell; Celestial Software, LLC
URL: http://www.celestial.com/  PO Box 820; 6641 E. Mercer Way
FAX:(206) 232-9186  Mercer Island, WA 98040-0820; (206) 236-1676

Suppose you were an idiot.  And suppose you were a member of Congress.  But
I repeat myself.  -- Mark Twain
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: first of misc questions....

2007-04-25 Thread Thomas Dickey
On Wed, Apr 25, 2007 at 10:31:45PM +0200, Irsla wrote:
> On 4/25/07, Matthew Seaman <[EMAIL PROTECTED]> wrote:
> >
> >   find . -type f \( -mtime 6 -o -mtime 29 \) -print0 | xargs -0 vi
> >
> 
> what about the -exec option of find ? I always wonder why people don't use 
> it.

it's simpler but not necessarily as efficient.

-- 
Thomas E. Dickey
http://invisible-island.net
ftp://invisible-island.net


pgpQclkpjotjq.pgp
Description: PGP signature


Re: first of misc questions....

2007-04-25 Thread Irsla

Hi,

On 4/25/07, Matthew Seaman <[EMAIL PROTECTED]> wrote:


   find . -type f \( -mtime 6 -o -mtime 29 \) -print0 | xargs -0 vi



what about the -exec option of find ? I always wonder why people don't use it.

find . -type f \( -mtime 6 -o -mtime 29 \) -exec vi {} \;

'{}" <= is the filename find found
you need a ';" to tell find that the command stops here (in case you
want to add more options to find) and the '\" is mandatory eitherwise
your SHELL will interfear.

btw don't forget the space between the '{}" and the '\;"


Regards,

--
A: Maybe because some people are too annoyed by top-posting.
Q: Why do I not get an answer to my question(s)?
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?

WAKIM Robert
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: first of misc questions....

2007-04-25 Thread Gary Kline
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
> 
> -- 
> This message has been scanned for viruses and
> dangerous content by MailScanner, and is
> believed to be clean.
> MailScanner thanks transtec Computers for their support.
> 

-- 
  Gary Kline  [EMAIL PROTECTED]   www.thought.org  Public Service Unix

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: first of misc questions....

2007-04-25 Thread Gary Kline
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-

-- 
  Gary Kline  [EMAIL PROTECTED]   www.thought.org  Public Service Unix

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: first of misc questions....

2007-04-25 Thread Derek Ragona

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


-Derek

--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
MailScanner thanks transtec Computers for their support.

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: first of misc questions....

2007-04-25 Thread Matthew Seaman
-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

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

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.

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-
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


first of misc questions....

2007-04-25 Thread Gary Kline
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!

 gary




  

-- 
  Gary Kline  [EMAIL PROTECTED]   www.thought.org  Public Service Unix

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"