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