Maybe by AWK: printing help diagonal matrix characters into line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Maybe by AWK: printing help diagonal matrix characters into line
# 1  
Old 04-13-2013
Maybe by AWK: printing help diagonal matrix characters into line

Hi Experts,

I want to print this charts diagonal data into straight lines.
This is a matrix 24X24 Horizontal and vertical.

- I want to print all the diagonal cutting characters into straight line:

Data:
Code:
E F S S A H A L L A T M C N O T S O B O D U Q H
I W I B N L O C N I L N L A N S I N G G L E B A
L R L C U Y V T P N F R A N K F O R T U R D P R
S A O B P D Y F C R V W C N O T S E L R A H C T
Q L P I Q X D V O N M Z E S I O B O E L H V V F
T E A D J L K N N O J V P Y R Y N I B B J X T O
I I N J W O C W C S W P P T T O P A A D C Q I R
G G A E C P O X O I Q U I H I N T H E E Z Z J D
V H I F C R R T R D G R C C N Y O E E N A W I A
U D D F O K E J D A N E Q A F N D E L N G Y E I
Q L N E L R L I G M K O D M R T A J E E E T L B
S E I R U F T A L A B U M O H T L W N Y C I L M
A I I S M A T J L E D Z U H N S N A A E V C I U
C F Q O B W I T U E P G X A C B M I Q H R N V L
R G D N U N L D C N E T L L R I G P T C Y O H O
A N S C S A O N E A E T N K L R R M E S H S S C
M I F I S K E S T S A A H O U R C Y I V U R A V
E R G T L D C S K P M E U B M T O L Q V U A N C
N P N Y I O U R H C F O S W R E V O D W M C O X
T S U V U G P O A A A I I E T L U A P T N I A S
O K O K U K E A T M R J N N M O N T G O M E R Y
N R P A Q N T N N R S T R D E N V E R H P Q A U
P G M K I Z A F A N O I J Z E S X P A K E P O T
X R X X C S L H G N A Y B Q M E L A S F G W B T



For Example desired output should be:
First : L1F1 character: [ Line 1 's Filed 1 ] , so to cover corner to corner as we progress.
Then : L1F2 + L2F1 [ Line 1 Field 2 + Line 2's Field 1 ]
Then : L1F3 + L2F2 + L3F1
Then : L1F4 + L2FF3 + L3F2 + L4F1
and so on ..


Code:
E
F I 
S W L
S I R S



Thanks,
# 2  
Old 04-13-2013
Interesting little problem! Try this:
Code:
awk     '       {for (i=1; i<=NF; i++) ALLAR [NR,i] = $i
                 for (j=NR; j>=1; j--) printf "%s ", ALLAR [NR-j+1,j]
                 printf "\n"
                }
        ' file
E 
F I 
S W L 
S I R S 
A B L A Q 
H N C O L T 
A L U B P E I 
L O Y P I A I G 
L C V D Q D N G V 
A N T Y X J J A H U 
T I P F D L W E I D Q 
M L N C V K O C F D L S 
C N F R O N C P C F N E A 
N L R V N N W O R O E I I C 
O A A W M O C X R K L R I F R 
T N N C Z J S O T E R U S Q G A 
S S K N E V W I R J L F M O D N M 
O I F O S P P Q D D I T A B N S I E 
B N O T I Y P U G A G A T W U C F R N 
O G R S O R T I R N M L J I N S I G P T 
D G T E B Y T H C E K A L T L A S T N S O 
U L U L O N O I C Q O B E U D O K L Y U K N 
Q E R R E I P N N A D U D E C N E D I V O R P 
H B D A L B A T Y F M M Z P N E S C O U K P G X

You may want to append a loop for the descending branch - take it as an exercise!
This User Gave Thanks to RudiC For This Post:
# 3  
Old 04-15-2013
Thanks , RudiC very much.. , Checking ll update further.

---------- Post updated at 05:40 AM ---------- Previous update was at 05:11 AM ----------

RudiC it worked very well for the first part to print diagonal values to straight line.
I am checking next part, and then from the other side diagonals.

Thanks a lot.

---------- Post updated 04-15-13 at 01:21 AM ---------- Previous update was 04-14-13 at 05:40 AM ----------

RudiC , this is a great code in your solution in the first part, till middle portion getting diagonally fields to straight line. However I am getting hard time iterating end portion to middle portion, for the two dimensional array.

24,24
24,23 23,24
24,22 23,23 22,24
24,21 23,22 22,23 21,24
..
..
24,1 23,2 22,3 .... ...... 1,24

Can you please advise, ..

Thanks.

Last edited by rveri; 04-15-2013 at 02:34 AM..
# 4  
Old 04-15-2013
You've got it all there, in the ALLAR array. Introduce an END section, a loop counter, and you're there!
# 5  
Old 04-19-2013
So - what solution did you end up with?
# 6  
Old 05-02-2013
RudiC,
Thanks .. , Actually in the matrix there are all the name of the US states 'Capital cities' :
Example :
Code:
ATLANTA BOISE BOSTON CARSONCITY DENVER DOVER ....

etc , I am trying to figure out their location with awk. Horizontal and Verticals are easy to compute in the matrix. However I have posted for the diagonals help.

Not yet end up with a solution yet, but the diagonal iterations are bit difficult to allginwith ALLAR [NR-j+1,j] code , both diagonal way , the solution you have given is just one way , 3 more way need to figure out , so I am still figuring it out.

Thanks...

Last edited by rveri; 05-02-2013 at 12:21 AM..
# 7  
Old 05-02-2013
Why do you need 3 more ways? Is this homework?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Printing string from last field of the nth line of file to start (or end) of each line (awk I think)

My file (the output of an experiment) starts off looking like this, _____________________________________________________________ Subjects incorporated to date: 001 Data file started on machine PKSHS260-05CP ********************************************************************** Subject 1,... (9 Replies)
Discussion started by: samonl
9 Replies

2. Shell Programming and Scripting

awk printing output to new line

Hi I have a file profile.txt with the below input: {"atgUserId":"736f14c4-eda2-4531-9d40-9de4d6d1fb0f","firstName":"donna","lastName":"biehler","email":"schoolathome42@live.com","receiveEmail":"y es"}, {"atgUserId":"c3716baf-9bf8-42da-8a44-a13fff68d20f","firstName":"Gilberto... (6 Replies)
Discussion started by: ankur328
6 Replies

3. Shell Programming and Scripting

Matching and printing line with awk

Hi there, I'm trying to use awk to print out the entire line that contains a match to a certain regex and then append some text,plus the match to the end of the line. So far I have: awk -F: '{print "RG:Z:" $2}' file Which prints out the match I want plus the additional text, but I'm stuck... (3 Replies)
Discussion started by: jim_lad
3 Replies

4. Shell Programming and Scripting

Printing characters at specific position in line

Hi, I am trying to get an output like : +----------------------------------+ ----------- + + some variable substitution + some text + Is there a way I can specify in printf (in ksh) the particular position I want to print a character, and also repeat a character from... (1 Reply)
Discussion started by: neil.k
1 Replies

5. Shell Programming and Scripting

help printing two consecutive columns, every twenty in a large matrix

Hi, I'm having a problem printing two consecutive columns, as I iterate through a large matrix by twenty columns and I was looking for a solution. My input file looks something like this 1 id1 A1 A2 A3 A4 A5 A6....A20 A21 A22 A23....A4001 A4002 2 id2 B1 B2 B3 B4 B5 B6... 3 id3 ... 4 id4... (8 Replies)
Discussion started by: flotsam
8 Replies

6. Shell Programming and Scripting

diagonal matrix to square matrix

Hello, all! I am struggling with a short script to read a diagonal matrix for later retrieval. 1.000 0.234 0.435 0.123 0.012 0.102 0.325 0.412 0.087 0.098 1.000 0.111 0.412 0.115 0.058 0.091 0.190 0.045 0.058 1.000 0.205 0.542 0.335 0.054 0.117 0.203 0.125 1.000 0.587 0.159 0.357... (11 Replies)
Discussion started by: yifangt
11 Replies

7. Shell Programming and Scripting

printing last two characters of each line

Hello, any trick to print line number and last two characters of each line ? (4 Replies)
Discussion started by: Bashar
4 Replies

8. Shell Programming and Scripting

Printing a specific line using AWK

Hi, I have a script that fetches only specific information from fcinfo command. Below is a portion of the script. #!/usr/bin/ksh set -x HBA_COUNT=`sudo fcinfo hba-port | grep -i state | awk 'END{print NR}'` echo "$HBA_COUNT HBAs exist" echo '........' INDEX=1 while $INDEX -le... (2 Replies)
Discussion started by: jake_won
2 Replies

9. Shell Programming and Scripting

printing a line number using awk

Hi Chaps, I'm trying to print the line number of a comma delimited file where the second field in the line is blank using AWK. Here is the code I have so far where am I going wrong. It is the last column in the file. nawk -v x==0 'BEGIN {FS=",";OFS=","} x++ if ($2 == " ") print $x' bob.tst ... (3 Replies)
Discussion started by: rjsha1
3 Replies

10. Linux

Regarding Dot Matrix Printing

Hi all, What I want is that can we manage printing a text file on a Dot Matrix printer installed on a Linux machine and the printer should not take the normal A4 format, but should print only to the extent the text file has text in it. What happen usually is that when we give print comand to any... (0 Replies)
Discussion started by: aman_mlt
0 Replies
Login or Register to Ask a Question