home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / unix / shell / 3911 < prev    next >
Encoding:
Text File  |  1992-09-11  |  1.2 KB  |  44 lines

  1. Newsgroups: comp.unix.shell
  2. 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
  3. From: hofer@Informatik.TU-Muenchen.DE (Robert Hofer)
  4. Subject: Re: Substring of a file name
  5. References: <37016@uflorida.cis.ufl.edu> <JDELL.92Sep10180225@golda.mit.edu> <02tT03R280oV00@amdahl.uts.amdahl.com>
  6. Sender: news@Informatik.TU-Muenchen.DE (USENET Newssystem)
  7. Organization: Technische Universitaet Muenchen, Germany
  8. Date: Fri, 11 Sep 1992 20:15:44 GMT
  9. Message-ID: <hofer.716242544@hphalle0>
  10. Lines: 32
  11.  
  12. Hi!
  13.  
  14. Dont forget the ksh feature "variable substitution" with #, ##, %, %%
  15. Here a short example:
  16.  
  17. #!/bin/ksh
  18.  
  19. #set -x +v
  20. a=${1%%[0-9][0-9][0-9][0-9]}
  21. b=${1##$a}
  22. if [ "$b" = "" ]; then
  23.     echo Cant split $1
  24. else
  25.     echo $1 = \($a\)\($b\)
  26. fi
  27.  
  28. And for your problem it looks like ...
  29.  
  30. echo *[0-9][0-9][0-9][0-9] | tr ' ' '\012' |
  31.     while read fn; do
  32.         if [ ! -d $fn -a ( -f $fn -o -L $fn ) ]; then
  33.             part1=${fn%%[0-9][0-9][0-9][0-9]}
  34.             part2=${fn##$part1}
  35.             ... do the rest ...
  36.         fi
  37.     done
  38.  
  39. Hope this helps,
  40. Robert
  41. -- 
  42. | Robert Hofer TU Muenchen             local ::= informatik.tu-muenchen.de
  43. | WIN: hofer@{local}                   UUCP: hofer%{local}@unido.uucp 
  44.