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

  1. Newsgroups: comp.unix.shell
  2. Path: sparky!uunet!wupost!zaphod.mps.ohio-state.edu!news.acns.nwu.edu!nucsrl!ddsw1!dattier
  3. From: dattier@ddsw1.mcs.com (David W. Tamkin)
  4. Subject: Re: Substring of a file name
  5. Message-ID: <BuHyHw.3o1@ddsw1.mcs.com>
  6. Organization: Contributor Account at ddsw1, Chicago, Illinois  60657
  7. References: <37016@uflorida.cis.ufl.edu> <JDELL.92Sep10180225@golda.mit.edu>
  8. Distribution: usa
  9. Date: Sun, 13 Sep 1992 03:17:55 GMT
  10. Lines: 27
  11.  
  12. jdell@golda.mit.edu (John Ellithorpe) wrote in
  13. <JDELL.92Sep10180225@golda.mit.edu>:
  14.  
  15. | On 10 Sep 92 15:15:41 GMT, urs@carp.cis.ufl.edu (Uppili Srinivasan) said:
  16.  
  17. | > I need to write a script to read a substring of some of the filenames
  18. | > in a directory. (i.e) if xy1992 is the name i need to read the last four
  19. | > letters only. I guess 'awk' is ideal for this . But I am curious to
  20. | > know the other ways of doing this.
  21.  
  22. | Well, if you knew that the first couple of characters were always characters
  23.  
  24. [I assume that Mr. Ellithorpe meant that they were always lower-case letters.]
  25.  
  26. | then you could use sed:
  27. | substring = `echo $file | sed -e 's/^[a-z][a-z]//'`
  28. | which would just delete out the first couple of characters.  Hope this
  29. | helps.
  30.  
  31. If you knew you always needed the last four characters, you could do this:
  32.  
  33. substring=`echo $filename | sed 's/.*\(....\)/\1/'`
  34.  
  35. David W. Tamkin   Box 59297   Northtown Station, Illinois  60659-0297
  36. dattier@ddsw1.mcs.com    CompuServe: 73720,1570    MCI Mail: 426-1818
  37.