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

  1. Newsgroups: comp.unix.shell
  2. Path: sparky!uunet!ftpbox!motsrd!mothost!schbbs!maccvm.corp.mot.com!W10075
  3. From: W10075@maccvm.corp.mot.com (Stephen Weet)
  4. Subject: Re: Substring of a file name
  5. Organization: Motorola
  6. Date: 11 Sep 1992 03:42:46 CDT
  7. Message-ID: <1992Sep11.090613.8831@schbbs.mot.com>
  8. Sender: news@schbbs.mot.com (Net News)
  9. Nntp-Posting-Host: maccvm.corp.mot.com
  10. Lines: 49
  11.  
  12. ------------------------- Original Article -------------------------
  13. Path: schbbs!mothost!ftpbox!uunet!gatech!uflorida!carp.cis.ufl.edu!urs
  14. From: urs@carp.cis.ufl.edu (Uppili Srinivasan)
  15. Newsgroups: comp.unix.shell
  16. Subject: Substring of a file name
  17. Message-ID: <37016@uflorida.cis.ufl.edu>
  18. Date: 10 Sep 92 15:15:41 GMT
  19. Sender: news@uflorida.cis.ufl.edu
  20. Distribution: usa
  21. Organization: Univ. of Florida CIS Dept.
  22. Lines: 15
  23. Nntp-Posting-Host: carp.cis.ufl.edu
  24.  
  25. Hi,
  26.  
  27. I need to write a script to read a substring of some of the filenames
  28.  
  29. in a directory. (i.e) if xy1992 is the name i need to read the last four
  30.  
  31. letters only. I guess 'awk' is ideal for this . But I am curious to
  32.  
  33. know the other ways of doing this.
  34.  
  35.  
  36. Thanx in advance
  37.  
  38. My e-mail address : urs@carp.cis.ufl.edu
  39. ------------------------------------------------------------------------
  40.  
  41. If you know the length of the filename in advance you can use the cut
  42. command e.g     echo filename | cut -c5-8  will give you columns
  43. 5 to 8.
  44.  
  45.    If you do not know the length of the filename or if there is no
  46.    pattern you can go to awk (Probably the easiest) or try this :-
  47.  
  48.  
  49.         FLENGTH=`echo $filename |wc -l`
  50.         echo $filename | cut -c`expr $FL - 4 `-`expr $FL - 1 `
  51.  
  52.    BEWARE :- Make sure all the spaces are in around expr's operatiors.
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.