Shell script, awk implements row and column conversions

Source: Internet
Author: User

[Email protected] study]#Cat fileZhang San languageBayiZhang San MathematicsBayiJohn Doe Language theJohn Doe Mathematics -Harry LanguageBayiHarry Mathematics -Harry English -How to implement for the following sort??? Bayi     Bayi     the     -    Bayi     -    -Chinese Mathematics Chinese Mathematics Chinese Mathematics English Zhang Sanzhang Harry Harry Harry the following is the thinking analysis: Zhang San ChineseBayiZhang San MathematicsBayiJohn Doe Language theJohn Doe Mathematics -Harry LanguageBayiHarry Mathematics -Harry English - for(i=1; i<=nf;i++) a[nr,i]=$i [NR i]=$ia [1,1]= $i =$1=1a[1,2]= $i =$1=2a[1,3]= $i =$1=3a[2,1]= $i =$1=1a[2,2]= $i =$1=2a[2.3]= $i =$1=3a[3,1]= $i =$1=1a[3,2]= $i =$1=2a[3,3]= $i =$1=3a[4,1]= $i =$1=1a[4,2]= $i =$1=2a[4.3]= $i =$1=3a[5,1]= $i =$1=1a[5,2]= $i =$1=2a[5,3]= $i =$1=3a[6,1]= $i =$1=1a[6,2]= $i =$1=2a[6,3]= $i =$1=3a[7,1]= $i =$1=1a[7,2]= $i =$1=2a[7,3]= $i =$1=3the values of these arrays correspond to the above one by one for the following sortBayi     Bayi     the     -    Bayi     -    -Chinese Mathematics Chinese Mathematics Chinese Mathematics English Zhang Sanzhang Harry Harry Harry then their corresponding array variable is: a[1,3] A[2.3] A[3,3] A[4.3] A[5,3] A[6,3] A[7.3]a[1,2] A[2,2] A[3,2] A[4,2] A[5,2] A[6,2] A[7,2]a[1,1] A[2,1] A[3,1] A[4,1] A[5,1] A[6,1] A[7,1] You can use the 2 for loop to control the corresponding array of the following table to remove the corresponding values for(i=nf;i>=1; i--) Output i=3 2 1(3>i>1) for(j=1; j<=nr;j++) Output j=1 2 3 4 5 6 7(1<j<7) When I= 3 o'clock j=1,2,3,4,5,6,7a[j,i] Output a[1,3] A[2,3] A[3,3] A[4,3] A[5,3] A[6,3] A[7,3] when I= 2 o'clock j=1,2,3,4,5,6,7a[j,i] Output a[1,2] A[2,2] A[3,2] A[4,2] A[5,2] A[6,2] A[7,2] when I= 2 o'clock j=1,2,3,4,5,6,7a[j,i] Output a[1,1] A[2,1] A[3,1] A[4,1] A[5,1] A[6,1] A[7,1][[email protected] study]#Cat file|awk '{for (i=1;i<=nf;i++) a[nr,i]= $i}end{for (i=nf;i>=1;i--) {for (j=1;j<=nr;j++) {printf a[j,i] ""}print Xxoo} }'Bayi Bayi  the  - Bayi  -  -Chinese Mathematics Chinese Mathematics Chinese Mathematics English Zhang Sanzhang Harry Harry Harry

Shell script, awk implements row and column conversions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.