home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / unix / question / 10153 < prev    next >
Encoding:
Internet Message Format  |  1992-08-18  |  1.1 KB

  1. Path: sparky!uunet!wupost!darwin.sura.net!haven.umd.edu!mimsy!lhc!moguls!berman
  2. From: berman@nlm.nih.gov (Lew Berman)
  3. Newsgroups: comp.unix.questions
  4. Subject: grep for number of character string
  5. Message-ID: <1992Aug18.140346.3939@nlm.nih.gov>
  6. Date: 18 Aug 92 14:03:46 GMT
  7. Sender: usenet@nlm.nih.gov (usenet news poster)
  8. Reply-To: berman@nlm.nih.gov
  9. Organization: National Library of Medicine
  10. Lines: 45
  11.  
  12. How can I determine if a value is a string or an integer within a 
  13. bourne shell script?  For example, if a file exists such that
  14. each line may contain a number (integer) or a string (which can
  15. be alpha-numeric) how do I determine which it is?  That is to say,
  16. if I cat the file into an argument and then run this data through a
  17. for loop how do I test each element?
  18.  
  19. Example shell script:
  20. #! /bin/sh
  21. data=`cat $1`
  22.  
  23. for i in $data
  24. do
  25.  
  26.     .....test for integer of alphanumeric string.....
  27.     
  28. done
  29.  
  30.  
  31. Example data file:
  32.  
  33. 345
  34. 5467
  35. 234
  36. 2
  37. 3
  38. 456
  39. 730
  40. aabbccdd
  41. sffeetr$%^
  42. 4566KKLKLK        <- not a number
  43. lij56            <- not a number
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51. Please respond by sending me e-mail.
  52.  
  53. Thanks,
  54.  
  55. Lew Berman
  56. National Library of Medicine
  57.