home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.shell
- Path: sparky!uunet!ftpbox!motsrd!mothost!schbbs!maccvm.corp.mot.com!W10075
- From: W10075@maccvm.corp.mot.com (Stephen Weet)
- Subject: Re: Substring of a file name
- Organization: Motorola
- Date: 11 Sep 1992 03:42:46 CDT
- Message-ID: <1992Sep11.090613.8831@schbbs.mot.com>
- Sender: news@schbbs.mot.com (Net News)
- Nntp-Posting-Host: maccvm.corp.mot.com
- Lines: 49
-
- ------------------------- Original Article -------------------------
- Path: schbbs!mothost!ftpbox!uunet!gatech!uflorida!carp.cis.ufl.edu!urs
- From: urs@carp.cis.ufl.edu (Uppili Srinivasan)
- Newsgroups: comp.unix.shell
- Subject: Substring of a file name
- Message-ID: <37016@uflorida.cis.ufl.edu>
- Date: 10 Sep 92 15:15:41 GMT
- Sender: news@uflorida.cis.ufl.edu
- Distribution: usa
- Organization: Univ. of Florida CIS Dept.
- Lines: 15
- Nntp-Posting-Host: carp.cis.ufl.edu
-
- Hi,
-
- 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.
-
-
- Thanx in advance
-
- My e-mail address : urs@carp.cis.ufl.edu
- ------------------------------------------------------------------------
-
- If you know the length of the filename in advance you can use the cut
- command e.g echo filename | cut -c5-8 will give you columns
- 5 to 8.
-
- If you do not know the length of the filename or if there is no
- pattern you can go to awk (Probably the easiest) or try this :-
-
-
- FLENGTH=`echo $filename |wc -l`
- echo $filename | cut -c`expr $FL - 4 `-`expr $FL - 1 `
-
- BEWARE :- Make sure all the spaces are in around expr's operatiors.
-
-
-
-
-
-
-
-
-