[comp.unix.questions] Globbing in csh

armstron@cs.arizona.edu (Jim Armstrong) (02/14/91)

Is is possible to match a group of files in alphabetic order using
globbing in csh?  For example my dir looks like this:
	able	david	greedy	jolly  .....
	baker   emery   handy	kape   .....
	cain	frank	intro	lemma  .....

I want to cat all files > george (lexicographically).

Maybe something like [g-z]* but that only looks at the first
letter and allows something like gary.

Can anyone help me please?


-- 
Jim Armstrong			  "The nonpayment and subsequent abuse of
armstron@cs.arizona.edu		  socially powerless athletes is simply a
{uunet|noao}!arizona!armstron     form of modern-day slavery" --Rick Telander

merlyn@iwarp.intel.com (Randal L. Schwartz) (02/14/91)

In article <857@caslon.cs.arizona.edu>, armstron@cs (Jim Armstrong) writes:
| Is is possible to match a group of files in alphabetic order using
| globbing in csh?  For example my dir looks like this:
| 	able	david	greedy	jolly  .....
| 	baker   emery   handy	kape   .....
| 	cain	frank	intro	lemma  .....
| 
| I want to cat all files > george (lexicographically).
| 
| Maybe something like [g-z]* but that only looks at the first
| letter and allows something like gary.
| 
| Can anyone help me please?

Hmm.  Not in csh.  But with a little assist from Perl:

cat `ls | perl -ne 'print if $_ gt "george"'`

Or, doing it all in Perl (catting and everything):

perl -e '@ARGV = grep($_ gt "george",<*>); while (<>) {	print; }'

Just another Perl hacker,
-- 
/=Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ==========\
| on contract to Intel's iWarp project, Beaverton, Oregon, USA, Sol III      |
| merlyn@iwarp.intel.com ...!any-MX-mailer-like-uunet!iwarp.intel.com!merlyn |
\=Cute Quote: "Intel: putting the 'backward' in 'backward compatible'..."====/

darcy@druid.uucp (D'Arcy J.M. Cain) (02/15/91)

In article <857@caslon.cs.arizona.edu> Jim Armstrong writes:
>Is is possible to match a group of files in alphabetic order using

Here is a general solution rather than a csh one:

ls | awk '{ if ($1 == "george") {start = 1} else if (start) print ;}'

Or even simpler:

ls | sed '1,/george/d'

So your example would be:

cat `ls | sed '1,/george/d'` > out_file

-- 
D'Arcy J.M. Cain (darcy@druid)     |
D'Arcy Cain Consulting             |   There's no government
West Hill, Ontario, Canada         |   like no government!
+1 416 281 6094                    |

armstron@cs.arizona.edu (Jim Armstrong) (02/16/91)

In article <1991Feb15.135812.5010@druid.uucp> darcy@druid.uucp (D'Arcy J.M. Cain) writes:
 
>ls | sed '1,/george/d'
>So your example would be:
>cat `ls | sed '1,/george/d'` > out_file

Thanks a lot.  Now I would like to generalize it using an alias.

I tried  alias mycat "cat `ls | sed '1,/\!*/d'` | less"
but it didn't work.

Could you help me again?



-- 
Jim Armstrong			  "The nonpayment and subsequent abuse of
armstron@cs.arizona.edu		  socially powerless athletes is simply a
{uunet|noao}!arizona!armstron     form of modern-day slavery" --Rick Telander

jik@athena.mit.edu (Jonathan I. Kamens) (02/18/91)

  Using the "makealias" and "quote" aliases by Dan Bernstein (brnstnd@nyu.edu):

    % makealias mycat
    cat `ls | sed '1,/!*/d'` | less
    alias mycat 'cat `ls | sed '\''1,/\!*/d'\''` | less'

I typed the "makealias mycat" command and the line starting with "cat", and
got back an alias with all of the quoting correctly done.  That line is what
you would use to define the alias.

  And here are Dan's aliases, in case you want to do this again with something
else:

    alias quote     "/bin/sed 's/\\!/\\\\\!/g' | /bin/sed 's/'\\\''/'\\\'\\\\\\\'\\\''/g' | /bin/sed 's/^/'\''/' | /bin/sed 's/"\$"/'\''/'"
    alias makealias "quote | /bin/sed 's/^/alias \!:1 /' \!:2*"

Pretty gross, but they do the job....

-- 
Jonathan Kamens			              USnail:
MIT Project Athena				11 Ashford Terrace
jik@Athena.MIT.EDU				Allston, MA  02134
Office: 617-253-8085			      Home: 617-782-0710