home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!wupost!darwin.sura.net!haven.umd.edu!mimsy!lhc!moguls!berman
- From: berman@nlm.nih.gov (Lew Berman)
- Newsgroups: comp.unix.questions
- Subject: grep for number of character string
- Message-ID: <1992Aug18.140346.3939@nlm.nih.gov>
- Date: 18 Aug 92 14:03:46 GMT
- Sender: usenet@nlm.nih.gov (usenet news poster)
- Reply-To: berman@nlm.nih.gov
- Organization: National Library of Medicine
- Lines: 45
-
- How can I determine if a value is a string or an integer within a
- bourne shell script? For example, if a file exists such that
- each line may contain a number (integer) or a string (which can
- be alpha-numeric) how do I determine which it is? That is to say,
- if I cat the file into an argument and then run this data through a
- for loop how do I test each element?
-
- Example shell script:
- #! /bin/sh
- data=`cat $1`
-
- for i in $data
- do
-
- .....test for integer of alphanumeric string.....
-
- done
-
-
- Example data file:
-
- 345
- 5467
- 234
- 2
- 3
- 456
- 730
- aabbccdd
- sffeetr$%^
- 4566KKLKLK <- not a number
- lij56 <- not a number
-
-
-
-
-
-
-
- Please respond by sending me e-mail.
-
- Thanks,
-
- Lew Berman
- National Library of Medicine
-