![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Array with special Characters | donaldfung | UNIX for Dummies Questions & Answers | 1 | 06-08-2008 01:18 PM |
| How to declare an array to take more than 10,000 characters | pinky | Shell Programming and Scripting | 0 | 01-15-2008 10:38 PM |
| create array holding characters from sring then echo array. | rorey_breaker | Shell Programming and Scripting | 5 | 09-28-2007 09:42 AM |
| Display special characters | BCarlson | Shell Programming and Scripting | 2 | 10-06-2006 10:59 AM |
| Display EBCDIC as Characters | LouPelagalli | AIX | 1 | 08-09-2005 03:07 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
2D Array to display characters
Hi All,
I have a series of number which indicates the coordinates where 0104 indicates X-coord = 01 and Y-coord = 04 and i want characters to form up in accordance to the coordinates given. Can any expert give me an example of 2D array code using csh or awk or perl such that the code can display the characters below ? EG: Inputfile: 0101 A 0102 B 0103 C 0104 D 0201 E 0202 F 0203 G 0204 H 0301 I 0302 J 0303 K 0304 L Code:
04 D H L 03 C G K 02 B F J 01 A E I 01 02 03 Last edited by Raynon; 02-27-2008 at 07:26 AM.. |
|
||||
|
Hi Klashxx,
Your code is really cool. Thks , it works up till a 9x9 matrix. However, I tried the code with x-coordinates 10 and above and it doesn't work. Can you help ? EG: Inputfile: 0101 A 0102 B 0103 C 0104 D 0201 E 0202 F 0203 G 0204 H 0301 I 0302 J 0303 K 0304 L 1001 M 1002 N |
|
|||||
|
Ok, it was a conversion problem, so:
Code:
> cat file 0101 A 0102 B 0103 C 0104 D 0201 E 0202 F 0203 G 0204 H 0301 I 0302 J 0303 K 0302 L 0903 U 1001 M 1002 N 1104 Ñ 1504 F 2005 N Code:
>awk '{
X[$2]=substr($1,1,2)
Y[$2]=substr($1,3)
}
END {
for ( y in Y)
for ( x in X )
if ( x == y )
{
dx=X[x]+0
dy=Y[y]+0
if ( dx >= max_x )
max_x=dx
if ( dy >= max_y )
max_y=dy
f[dx,dy]=x
}
for (i=max_y;i>=1;i--)
{
printf("%.2d",i)
for (j=1;j<=max_x;j++)
printf(" %2s",f[j,i])
printf("\n")
}
printf(" ")
for (j=1;j<=max_x;j++)
printf("%.2d ",j)
print
} ' file
05 N
04 D H Ñ F
03 C G K U
02 B L
01 A E I M
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20
Last edited by Klashxx; 02-27-2008 at 10:25 AM.. Reason: bug solved |
|
||||
|
Hi Klashxx,
Strange, i tried to use yr modified code but some strange characters appear at the end of output in blue. Can you give some advice on that Code:
$ cat input1 0101 A 0102 B 0103 C 0104 D 0201 E 0202 F 0203 G 0204 H 0301 I 0302 J 0303 K 0302 L 0801 Z 0903 U 1001 M 1002 N $ awk -f 2d_array input1 04 D H 03 C G K U 02 B F L N 01 A E I Z M 01 02 03 04 05 06 07 08 09 10 1002 N |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|