Awk's output doesn't go as well as I want.

Asked 2 years ago, Updated 2 years ago, 304 views

When you actually run the code below,

203100B
203101K
.
.
.

I would like you to write A for all the characters.
Could you tell me what's wrong?

#!/usr/bin/awk-f
US>BEGIN{

    for(i=0;i<=40;i++){
        zyu[i] = int(i/10)
            iti[i] = i%10
            check[i]=(33+zyu[i]*3+iti[i]*2)%11)%10

            if(check[i]=0)printf("2031%02d%1s\n", i, "B")
            else if(check[i]=1)printf("2031%02d%1s\n", i, "A")
            else if(check[i]=2)printf("2031%02d%1s\n", i, "K")
            else if(check[i]=3)printf("2031%02d%1s\n", i, "J")
            else if(check[i]=4)printf("2031%02d%1s\n", i, "H")
            else if(check[i]=5)printf("2031%02d%1s\n", i, "G")
            else if(check[i]=6)printf("2031%02d%1s\n", i, "F")
            else if(check[i]=7)printf("2031%02d%1s\n", i, "E")
            else if(check[i]=8)printf("2031%02d%1s\n", i, "D")
            else if(check[i]=9)printf("2031%02d%1s\n", i, "C")
    }
}

awk

2022-09-30 22:00

1 Answers

if statement (and else) has one =, so I think it's because it's substitution instead of comparison.

Use == to compare values.

Modification Example (Excerpt):

 if(check[i]==0)printf("2031%02d%1s\n", i, "B")
            else if(check[i]==1)printf("2031%02d%1s\n", i, "A")
            else if(check[i]==2)printf("2031%02d%1s\n", i, "K")
            else if(check[i]==3)printf("2031%02d%1s\n", i, "J")
            else if(check[i]==4)printf("2031%02d%1s\n", i, "H")
            else if(check[i]==5)printf("2031%02d%1s\n", i, "G")
            else if(check[i]==6)printf("2031%02d%1s\n", i, "F")
            else if(check[i]==7)printf("2031%02d%1s\n", i, "E")
            else if(check[i]==8)printf("2031%02d%1s\n", i, "D")
            else if(check[i]==9)printf("2031%02d%1s\n", i, "C")


2022-09-30 22:00

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.