Article View: comp.unix.shell
Article #13Re: Need script to find root of filename
From: Michael Lemke
Date: Thu, 29 Oct 1992 05:21
Date: Thu, 29 Oct 1992 05:21
42 lines
1728 bytes
1728 bytes
In article <1992Oct28.204157.14215@prl.dec.com> boyd@prl.dec.com (Boyd Roberts) writes:
>In article <guy.720279933@tdsb-s>, guy@mais.hydro.qc.ca (Guy Harel) writes:
>>
>> >carpenter@vixvax.mgi.com wrote:
>> >> I have a directory containing filenames of the form "*.[0-9]*",
>> >> and would like to write a csh script to print out the "root" of
>> >> each name. For example, if the names abc.def.012 and gh.ijkl.mno.987
>> >> appear in the directory, I would like to see abc.def and gh.ijkl.mno
>> >> printed out.
>>
>> I had fun trying the following:
>
>I'm sure you did.
>
>>
>> echo abc.def.ghi.123 | \
>> awk -F. '{ $x=$1 ; for ( i = 2 ; i < NF ; i++ ) $x=$x"."$i } END { print $x }'
>
>Could you make it a little more complex?
>
> prl313 ; echo abc.def.ghi.123 | sed 's/\(.*\)\..*/\1/'
> abc.def.ghi
>
>Nah, too simple.
>
How about
expr abc.def.ghi.123 : '\(.*\)\..*'
Nah, that's trivial. Sorry.
But
expr abc.def.ghi.123 : '\(.*\)\.[0-9].*'
is slightly more complex and matches exactly the poster's expression.
--
Michael Lemke
Astronomy, UT Austin, Texas
(michael@io.as.utexas.edu or UTSPAN::UTADNX::IO::MICHAEL [SPAN])
Technical Details
Message-ID:
<1992Oct29.052159.10455@chpc.utexas.edu>Path:
arc1-ca.pugleaf.net!sparky!uunet!ogicse!uwm.edu!zaphod.mps.ohio-state.edu!cs.utexas.edu!hermes.chpc.utexas.edu!aswx266References:
<1c25piINNqg2@s850.mwc.edu> <guy.720279933@tdsb-s> <1992Oct28.204157.14215@prl.dec.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!ogicse!uwm.edu!zaphod.mps.ohio-state.edu!cs.utexas.edu!hermes.chpc.utexas.edu!aswx266 From: aswx266@chpc.utexas.edu (Michael Lemke) Newsgroups: comp.unix.shell Subject: Re: Need script to find root of filename Message-ID: <1992Oct29.052159.10455@chpc.utexas.edu> Date: 29 Oct 92 05:21:59 GMT Article-I.D.: chpc.1992Oct29.052159.10455 References: <1c25piINNqg2@s850.mwc.edu> <guy.720279933@tdsb-s> <1992Oct28.204157.14215@prl.dec.com> Organization: The University of Texas System - CHPC Lines: 42