Reputation: 944
I am currently trying to work up a solution that generates strings based on the input.
When I execute the function
cat text | awk '{printf("%s global\n", $1);}'
in which text is
0_0_0_0_1_1_1_1 NO NO NO NO YES YES YES YES
and the output is
0_0_0_0_1_1_1_1 global
which is correct, but in some cases the text can be
K_0_0_0_0_1_1_1_1 NO NO NO NO YES YES YES YES
in which case the following command, would not work, as the output should be
K_0_0_0_0_1_1_1_1 Kai
how do i make awk
know when it should output Kai or global?
Upvotes: 1
Views: 49
Reputation: 785146
You can use conditional print
:
awk '{print $1, ($1 ~ /^K_/ ? "Kai" : "global")}' file
0_0_0_0_1_1_1_1 global
K_0_0_0_0_1_1_1_1 Kai
Upvotes: 3