Sponsored Content
Top Forums Shell Programming and Scripting 2D Array to display characters Post 302170948 by Klashxx on Wednesday 27th of February 2008 06:26:48 AM
Old 02-27-2008
This way:
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=sprintf("%d",X[x])
        dy=sprintf("%d",Y[y])
        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
 4  D  H  L
 3  C  G  K
 2  B  F  J
 1  A  E  I
    1  2  3

 

10 More Discussions You Might Find Interesting

1. AIX

Display EBCDIC as Characters

Hi, Does anybody have a command to share that will display EBCDIC files as character? I have od -x -A d which will display hex as follows f0f1 f4f3 f0f0 f0f0 f0f6 f1f4 f6f3 f3f0 f3f9 f8f3 f1f6 f8f2 f860 d1e4 d360 f2f0 f0f5 4000 0000 5014 8c00 0000 0000 0c00 0000 0000 0d00 0000 5014 8c00... (1 Reply)
Discussion started by: LouPelagalli
1 Replies

2. UNIX for Dummies Questions & Answers

Garbage characters in display

:confused: I recently left managment and came back to AIX administration. So I am a bit rusty to say the least. The issue I am having is with the term settings when I either simply telnet to my AIX unit or even when I use an emulator like puTTY or a VAR provided one. Once I am logged into... (0 Replies)
Discussion started by: Haleja001
0 Replies

3. Shell Programming and Scripting

Display special characters

I have a file that evidently has some special characters in it. Is there a Unix command that I can use tp display the file so I can see the octal or hex values? (2 Replies)
Discussion started by: BCarlson
2 Replies

4. Shell Programming and Scripting

create array holding characters from sring then echo array.

Hi, I wish to store $string1 in $string1array a character in each array element. Then i wish to echo the entire array to the screen so that it reads as the normal string again. I have been trying with the code below but does not work. Please help... To put string into array: ... (5 Replies)
Discussion started by: rorey_breaker
5 Replies

5. UNIX for Dummies Questions & Answers

Display the contents of an array

Hi i have just registered So i am at university studying forensic computing and we have to learn c++ i have never done anything with c++ before and i am abit stuck i need to create a programme to display the contents of an array of characters forwards and in reverse Can anyone help me... (1 Reply)
Discussion started by: RossMc
1 Replies

6. UNIX and Linux Applications

Display non-english characters in shell

I don't know if this is the correct thread to post. If not tell me please. I have a script to make some queries to a Spanish Dictionay (Real Academia Espaņola) as follows: lynx -dump --nolist "buscon.rae.es/draeI/SrvltGUIBusUsual?TIPO_ HTML=2&LEMA="$1 It works this way: ./rae word ... (1 Reply)
Discussion started by: agasamapetilon
1 Replies

7. Shell Programming and Scripting

Display first few characters only

I have a file with one or two lengthy lines like.... masterUserID = 'S' OR masterUserID = 'S' OR masterUserID = 'S' (many many more times) How do I display only the first few hundred characters from each line. (1 Reply)
Discussion started by: shantanuo
1 Replies

8. UNIX for Dummies Questions & Answers

Display only the first two characters of all the lines from a file.

how do i Display only the first two characters of all the lines from a file.? (1 Reply)
Discussion started by: ritusubash
1 Replies

9. Shell Programming and Scripting

Store all the passed arguments in an array and display the array

Hi I want to write a script which store all the parameters passed to the script into an array. Once it is stored I want scan through the array and and delete those files for last month present inside the directory. The files in directory is appneded with YYYY_MM_DD. I want to know how can I... (3 Replies)
Discussion started by: dgmm
3 Replies

10. Shell Programming and Scripting

Pass array to a function and display the array

Hi All I have multiple arrays like below. set -A val1 1 2 4 5 set -A val2 a b c d . . . Now i would like to pass the individual arrays one by one to a function and display/ do some action. Note : I am using ksh Can you please advise any solution... Thanks in advance. (7 Replies)
Discussion started by: Girish19
7 Replies
Math(3pm)						User Contributed Perl Documentation						 Math(3pm)

NAME
XRacer::Math - Library of miscellaneous 3D math functions used by XRacer tools. SYNOPSIS
use XRacer::Math; Basic mathematics: $midpoint = midpoint (@vertices); $normalize_vector = normalize ($vector); $magnitude = magnitude ($vector); $magnitude = magnitude_in_direction ($v1, $v2); $angle = angle_between ($v1, $v2); $vector = multiply_scalar_vector ($scalar, $vector); $matrix = matrix_multiply ($a, $b); $vector = matrix_vector_multiply ($m, $v); $sum = sum_vectors (@vectors); $vector = subtract_vectors ($vector1, $vector2); ($min_x, $max_x, $min_y, $max_y, $min_z, $max_z) = bbox (@vertices); Dot products and cross products: $product = dot_product ($vector1, $vector2); $vector = cross_product ($vector1, $vector2); Distances: $distance = distance ($point1, $point2); $distance = distance_point_to_line ($line, $point); $distance = distance_point_to_plane ($plane, $point); $distance = minimum_distance_between_two_lines ($line1, $line2); Planes: $plane = plane_coefficients ($point1, $point2, $point3); $boolean_result = is_coplanar ($point1, $point2, $point3, $point4); $normal = normal ($plane); $unit_normal = unit_normal ($plane); $line = intersection_of_two_planes ($plane1, $plane2); $point = intersection_line_and_plane ($plane, $line); ($inside_face, $outside_face) = split_convex_face_in_place ($face, $plane); Line segments: $lineseg = line_segment ($point1, $point2); Cylinders: $boolean_result = line_intersects_cylinder ($line, $cylinder); DESCRIPTION
This library contains miscellaneous functions which are used by the XRacer track building tools. The functions perform various 3D mathematical operations on points (vertices), vectors, lines and planes. Points or vertices are represented by a reference to an array containing three elements. That is to say, to initialize a point, do this: $point = [ $x, $y, $z ]; Vectors are represented by a reference to an array containing three elements: $vector = [ $dx, $dy, $dz ]; Lines are represented by the formula: p + t.v where p is a point on the line and v is a vector parallel to the line. Therefore a line is simply a reference to a hash containing the point and vector: $line = {'p' => $point, 'v' => $vector}; A line segment is represented by the formula: p + t.v where a <= t <= b implying the following representation: $lineseg = { 'p' => $point, 'v' => $vector, 'a' => $a, 'b' => $b }; Notice that you can use a line segment wherever you would use a line. Cylinders are represented by the hash reference: $cylinder = { 'radius' => $radius, 'p' => $point, 'v' => $vector, 'a' => $a, 'b' => $b }; where $radius is the radius of the cylinder, and the other fields are a line segment running from the midpoint of one end of the cylinder to the midpoint of the other end of the cylinder. In other words, a cylinder is simply a line segment with added radius field. Planes are represented by the formula: ax + by + cz + d = 0 where a, b, c and d are coefficients which uniquely define the plane. A plane is a reference to an array containing these four constants: $plane = [ $a, $b, $c, $d ]; Use the "plane_coefficients" function to compute the four coefficients of a plane, given any three points (not colinear) on the plane. The following page was enormously useful in working out these formulae: "http://www.magic-software.com/ComputerGraphics.html" PACKAGE FUNCTIONS
$midpoint = midpoint (@vertices); Compute the midpoint (average) of a list of vertices. $distance = distance ($point1, $point2); Compute the distance between two points. $plane = plane_coefficients ($point1, $point2, $point3); Compute the four coefficients of a plane. The three points given as parameters lie on the plane, but must not be colinear. Returns a reference to the array of four coefficients. $boolean_result = is_coplanar ($point1, $point2, $point3, $point4); Return true if the four points given are coplanar. $distance = distance_point_to_line ($line, $point); Compute the shortest distance from a point to a line. $distance = distance_point_to_plane ($plane, $point); Compute the shortest distance from a point to a plane. This function preserves the sign of the distance, so $distance will be positive if the point is above/inside the plane and negative if the point is below/outside the plane. $normal = normal ($plane); Compute the normal vector to the plane. This vector is not unit length (see the "unit_normal" function for that). $unit_normal = unit_normal ($plane); Compute the unit length normal vector to a plane. $normalize_vector = normalize ($vector); Take a vector and return a normalized vector, of unit length. $magnitude = magnitude ($vector); Return the magnitude of a vector. $magnitude = magnitude_in_direction ($v1, $v2); Compute the magnitude of vector v1 in direction vector v2. If v1 == v2, then this returns 1. If v1 = -v2, this returns -1. If v1 is perpendicular to v2, this returns 0. $angle = angle_between ($v1, $v2); Return the angle (in radians) between two vectors. $vector = multiply_scalar_vector ($scalar, $vector); Multiply a scalar and a vector and return the result. $matrix = matrix_multiply ($a, $b); Multiply two matrices 4x4 together. The resulting matrix is returned. $vector = matrix_vector_multiply ($m, $v); Multiply a 4x1 vector and a 4x4 matrix together. The resulting 4x1 vector is returned. $sum = sum_vectors (@vectors); Sum a collection of vectors and return the result. $line = intersection_of_two_planes ($plane1, $plane2); Compute the intersection (a line) of two planes. If the two planes are coplanar or parallel, then this function will return undef. $point = intersection_line_and_plane ($plane, $line); Compute the intersection of a line with a plane. This returns a point. If the line and plane are parallel, it returns undef. ($inside_face, $outside_face) = split_convex_face_in_place ($face, $plane); Given a convex face, specified as follows: $face = [ $vertex0, $vertex1, ... ]; we split the face into two faces. The first face returned is inside the plane. The second face returned is outside the plane. $vector = subtract_vectors ($vector1, $vector2); Compute: "$vector1 - $vector2", and return the resulting vector. ($min_x, $max_x, $min_y, $max_y, $min_z, $max_z) = bbox (@vertices); Construct the bounding box (minima and maxima of each coordinate) of a list of vertices. $product = dot_product ($vector1, $vector2); Compute the dot product (a scalar number) of the two vector arguments. $vector = cross_product ($vector1, $vector2); Compute the cross product (a vector) of the two vector arguments. $distance = minimum_distance_between_two_lines ($line1, $line2); Compute the minimum distance between two lines. $lineseg = line_segment ($point1, $point2); Construct a line segment from $point1 to $point2. $boolean_result = line_intersects_cylinder ($line, $cylinder); Returns true if the $line intersects the $cylinder at any point. AUTHOR
Richard W.M. Jones, <rich@annexia.org> COPYRIGHT
XRacer is copyright (C) 1999-2000 Richard W.M. Jones (rich@annexia.org) and other contributors listed in the AUTHORS file. SEE ALSO
perl(1), xracer(6). perl v5.14.2 2000-02-19 Math(3pm)
All times are GMT -4. The time now is 05:50 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy