home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.shell
- Path: sparky!uunet!sun-barr!ames!haven.umd.edu!darwin.sura.net!Sirius.dfn.de!zrz.tu-berlin.de!math.fu-berlin.de!informatik.tu-muenchen.de!hphalle0!hofer
- From: hofer@Informatik.TU-Muenchen.DE (Robert Hofer)
- Subject: Re: Substring of a file name
- References: <37016@uflorida.cis.ufl.edu> <JDELL.92Sep10180225@golda.mit.edu> <02tT03R280oV00@amdahl.uts.amdahl.com>
- Sender: news@Informatik.TU-Muenchen.DE (USENET Newssystem)
- Organization: Technische Universitaet Muenchen, Germany
- Date: Fri, 11 Sep 1992 20:15:44 GMT
- Message-ID: <hofer.716242544@hphalle0>
- Lines: 32
-
- Hi!
-
- Dont forget the ksh feature "variable substitution" with #, ##, %, %%
- Here a short example:
-
- #!/bin/ksh
-
- #set -x +v
- a=${1%%[0-9][0-9][0-9][0-9]}
- b=${1##$a}
- if [ "$b" = "" ]; then
- echo Cant split $1
- else
- echo $1 = \($a\)\($b\)
- fi
-
- And for your problem it looks like ...
-
- echo *[0-9][0-9][0-9][0-9] | tr ' ' '\012' |
- while read fn; do
- if [ ! -d $fn -a ( -f $fn -o -L $fn ) ]; then
- part1=${fn%%[0-9][0-9][0-9][0-9]}
- part2=${fn##$part1}
- ... do the rest ...
- fi
- done
-
- Hope this helps,
- Robert
- --
- | Robert Hofer TU Muenchen local ::= informatik.tu-muenchen.de
- | WIN: hofer@{local} UUCP: hofer%{local}@unido.uucp
-