zsh-users
 help / color / mirror / code / Atom feed
* OT: How to list all but the last item
@ 2006-09-18 16:39 Meino Christian Cramer
  2006-09-18 17:02 ` Will Maier
  2006-09-18 17:17 ` Stephane Chazelas
  0 siblings, 2 replies; 5+ messages in thread
From: Meino Christian Cramer @ 2006-09-18 16:39 UTC (permalink / raw)
  To: zsh-users

Hi,

 may be this is a very stupid question...and may be I am blind...
 But...

 I want to contruct a loop like

 for i in `<cmd>`
 do
   <do something> ${i}
 done

 and <cmd> should return a list of items matched by a regexp
 or another kind of qualifier and skipping the last item.

 Example:

 ls -rtlc * | <???what???>

 would return every item in a directory exept the newest one.

 Is there any way to accomplish with something fitting in on
 a commandline???

 Thanks a lot for any hepl in advance!
 Keep zshing!
 mcc


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: OT: How to list all but the last item
  2006-09-18 16:39 OT: How to list all but the last item Meino Christian Cramer
@ 2006-09-18 17:02 ` Will Maier
  2006-09-18 17:17   ` Meino Christian Cramer
  2006-09-18 17:17 ` Stephane Chazelas
  1 sibling, 1 reply; 5+ messages in thread
From: Will Maier @ 2006-09-18 17:02 UTC (permalink / raw)
  To: zsh-users

On Mon, Sep 18, 2006 at 06:39:59PM +0200, Meino Christian Cramer wrote:
>  Example:
> 
>  ls -rtlc * | <???what???>
> 
>  would return every item in a directory exept the newest one.
> 
>  Is there any way to accomplish with something fitting in on
>  a commandline???

sed(1).

eg:

    /etc % jot 5
    1
    2
    3
    4
    5

    /etc % jot 5 | sed -e '$d'
    1
    2
    3
    4

-- 

[Will Maier]-----------------[willmaier@ml1.net|http://www.lfod.us/]


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: OT: How to list all but the last item
  2006-09-18 17:02 ` Will Maier
@ 2006-09-18 17:17   ` Meino Christian Cramer
  0 siblings, 0 replies; 5+ messages in thread
From: Meino Christian Cramer @ 2006-09-18 17:17 UTC (permalink / raw)
  To: willmaier; +Cc: zsh-users

From: Will Maier <willmaier@ml1.net>
Subject: Re: OT: How to list all but the last item
Date: Mon, 18 Sep 2006 12:02:57 -0500

> On Mon, Sep 18, 2006 at 06:39:59PM +0200, Meino Christian Cramer wrote:
> >  Example:
> > 
> >  ls -rtlc * | <???what???>
> > 
> >  would return every item in a directory exept the newest one.
> > 
> >  Is there any way to accomplish with something fitting in on
> >  a commandline???
> 
> sed(1).
> 
> eg:
> 
>     /etc % jot 5
>     1
>     2
>     3
>     4
>     5
> 
>     /etc % jot 5 | sed -e '$d'
>     1
>     2
>     3
>     4
> 
> -- 
> 
> [Will Maier]-----------------[willmaier@ml1.net|http://www.lfod.us/]
> 

...and then light strucks me! :)

Thanks a lot, Will!

Keep hacking!
mcc


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: OT: How to list all but the last item
  2006-09-18 16:39 OT: How to list all but the last item Meino Christian Cramer
  2006-09-18 17:02 ` Will Maier
@ 2006-09-18 17:17 ` Stephane Chazelas
  2006-09-18 17:23   ` Meino Christian Cramer
  1 sibling, 1 reply; 5+ messages in thread
From: Stephane Chazelas @ 2006-09-18 17:17 UTC (permalink / raw)
  To: zsh-users

On Mon, Sep 18, 2006 at 06:39:59PM +0200, Meino Christian Cramer wrote:
> Hi,
> 
>  may be this is a very stupid question...and may be I am blind...
>  But...
> 
>  I want to contruct a loop like
> 
>  for i in `<cmd>`
>  do
>    <do something> ${i}
>  done
> 
>  and <cmd> should return a list of items matched by a regexp
>  or another kind of qualifier and skipping the last item.
> 
>  Example:
> 
>  ls -rtlc * | <???what???>
> 
>  would return every item in a directory exept the newest one.

-c is to sort of the file change-status time. You want file
modification time, it's ls -rtl.

And it should be

ls -rtl | ...

Or

ls -rtld -- * | ...

>  Is there any way to accomplish with something fitting in on
>  a commandline???

ls -tl | tail +2

ls -trl | sed '$d'

Also:

ls -trld -- *(om[2,-1])

Also:

IFS=$'\n\n'
lines=( $(cmd) )
for line in "${(@)lines[1,-2]}"; do ...; done

-- 
Stéphane


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: OT: How to list all but the last item
  2006-09-18 17:17 ` Stephane Chazelas
@ 2006-09-18 17:23   ` Meino Christian Cramer
  0 siblings, 0 replies; 5+ messages in thread
From: Meino Christian Cramer @ 2006-09-18 17:23 UTC (permalink / raw)
  To: Stephane_Chazelas; +Cc: zsh-users

From: Stephane Chazelas <Stephane_Chazelas@yahoo.fr>
Subject: Re: OT: How to list all but the last item
Date: Mon, 18 Sep 2006 18:17:52 +0100

> On Mon, Sep 18, 2006 at 06:39:59PM +0200, Meino Christian Cramer wrote:
> > Hi,
> > 
> >  may be this is a very stupid question...and may be I am blind...
> >  But...
> > 
> >  I want to contruct a loop like
> > 
> >  for i in `<cmd>`
> >  do
> >    <do something> ${i}
> >  done
> > 
> >  and <cmd> should return a list of items matched by a regexp
> >  or another kind of qualifier and skipping the last item.
> > 
> >  Example:
> > 
> >  ls -rtlc * | <???what???>
> > 
> >  would return every item in a directory exept the newest one.
> 
> -c is to sort of the file change-status time. You want file
> modification time, it's ls -rtl.
> 
> And it should be
> 
> ls -rtl | ...
> 
> Or
> 
> ls -rtld -- * | ...
> 
> >  Is there any way to accomplish with something fitting in on
> >  a commandline???
> 
> ls -tl | tail +2
> 
> ls -trl | sed '$d'
> 
> Also:
> 
> ls -trld -- *(om[2,-1])
> 
> Also:
> 
> IFS=$'\n\n'
> lines=( $(cmd) )
> for line in "${(@)lines[1,-2]}"; do ...; done
> 
> -- 
> Stéphane
> 

Hi Stephane,

 thanks a lot for your reply! :)
 
 Now I have many solutions to choose from :))

 Keep hacking!
 mcc


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2006-09-18 17:23 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-09-18 16:39 OT: How to list all but the last item Meino Christian Cramer
2006-09-18 17:02 ` Will Maier
2006-09-18 17:17   ` Meino Christian Cramer
2006-09-18 17:17 ` Stephane Chazelas
2006-09-18 17:23   ` Meino Christian Cramer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).