home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / misc / 2928 < prev    next >
Encoding:
Text File  |  1992-09-03  |  1.1 KB  |  87 lines

  1. Newsgroups: comp.lang.misc
  2. Path: sparky!uunet!munnari.oz.au!manuel!huxley!aps583
  3. From: aps583@huxley.anu.edu.au (Anthony P Scott)
  4. Subject: AWK using an array to subscript an array??
  5. Message-ID: <1992Sep4.004020.26667@newshost.anu.edu.au>
  6. Originator: aps583@huxley
  7. Sender: news@newshost.anu.edu.au
  8. Organization: Australian National University
  9. Date: Fri, 4 Sep 92 00:40:20 GMT
  10. Lines: 75
  11.  
  12. Say for instance that I wanted to read a line of text containing
  13. one character and output
  14. that line in terms of the postion of the letters in the 
  15. alphabet.
  16.  
  17. ie  like:
  18.  
  19.  a
  20.  b
  21.  c
  22.  d
  23.  e
  24.  f
  25.  g
  26.  h
  27.  i
  28.  j
  29.  k
  30.  l
  31.  m
  32.  n
  33.  o
  34.  p
  35.  q
  36.  
  37. would be printed as:
  38. 1
  39.  2
  40.  3
  41.  4
  42.  5
  43.  6
  44.  7
  45.  8
  46.  9
  47.  10
  48.  11
  49.  12
  50.  13
  51.  14
  52.  15
  53.  16
  54.  17 
  55.  
  56. One way I visualized doing this is to read the alphabet into an array
  57. such as:
  58.  
  59. alph[a] = 1
  60. alph[b] = 2
  61. alph[c] = 3
  62. ...
  63.  
  64. ...
  65. alph[q] = 20
  66.  
  67. and then read the line of text into another array by
  68.  
  69. {
  70. line_arr[NR] = $1
  71. }
  72.  
  73.  and then using something like
  74.  
  75. for (i=i; i<=NR; i++) {
  76. alph_pos[i] = alph[line_arr[i]]
  77. print alph_pos[i]
  78. }
  79.  
  80. However this doesn't work.
  81.  
  82. Does any body have any suggestions?
  83.  
  84. Thanks in anticipation.
  85.  
  86. Tony Scott
  87.