Article View: comp.lang.misc
Article #1119AWK using an array to subscript an array??
From: Anthony P Scott
Date: Fri, 04 Sep 1992 00:40
Date: Fri, 04 Sep 1992 00:40
75 lines
1200 bytes
1200 bytes
Say for instance that I wanted to read a line of text containing
one character and output
that line in terms of the postion of the letters in the
alphabet.
ie like:
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
would be printed as:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
One way I visualized doing this is to read the alphabet into an array
such as:
alph[a] = 1
alph[b] = 2
alph[c] = 3
...
...
alph[q] = 20
and then read the line of text into another array by
{
line_arr[NR] = $1
}
and then using something like
for (i=i; i<=NR; i++) {
alph_pos[i] = alph[line_arr[i]]
print alph_pos[i]
}
However this doesn't work.
Does any body have any suggestions?
Thanks in anticipation.
Tony Scott
Technical Details
Message-ID:
<1992Sep4.004020.26667@newshost.anu.edu.au>Path:
arc1-ca.pugleaf.net!sparky!uunet!munnari.oz.au!manuel!huxley!aps583Show Full Headers
Complete Article Headers
Newsgroups: comp.lang.misc Path: arc1-ca.pugleaf.net!sparky!uunet!munnari.oz.au!manuel!huxley!aps583 From: aps583@huxley.anu.edu.au (Anthony P Scott) Subject: AWK using an array to subscript an array?? Message-ID: <1992Sep4.004020.26667@newshost.anu.edu.au> Originator: aps583@huxley Sender: news@newshost.anu.edu.au Organization: Australian National University Date: Fri, 4 Sep 92 00:40:20 GMT Lines: 75