2 deleted 6 characters in body; edited tags
source | link

I'm using a bash script. I have a tab delimited file with data that looks like

Afghanistan     AF      AFG     004
ALA     Aland Islands   AX      ALA     248
Albania AL      ALB     008
Algeria DZ      DZA     012

I want to rewrite the data like so

AF=AFG
AX=ALA
AL=ALB
DZ=DZA

which boils down to extracting the third to last token, writing an equals, and then printing the second to last token. I thought "awk" could help me, but I don't know how to say "second to last". This doesn't cut it

awk '{print $2=$3}' /tmp/country_data.tsv 

How can I extract the data in the way I want?

I'm using a bash script. I have a tab delimited file with data that looks like

Afghanistan     AF      AFG     004
ALA     Aland Islands   AX      ALA     248
Albania AL      ALB     008
Algeria DZ      DZA     012

I want to rewrite the data like so

AF=AFG
AX=ALA
AL=ALB
DZ=DZA

which boils down to extracting the third to last token, writing an equals, and then printing the second to last token. I thought "awk" could help me, but I don't know how to say "second to last". This doesn't cut it

awk '{print $2=$3}' /tmp/country_data.tsv 

How can I extract the data in the way I want?

I'm using a bash script. I have a tab delimited file with data that looks like

Afghanistan     AF      AFG     004
ALA     Aland Islands   AX      ALA     248
Albania AL      ALB     008
Algeria DZ      DZA     012

I want to rewrite the data like so

AF=AFG
AX=ALA
AL=ALB
DZ=DZA

which boils down to extracting the third to last token, writing an equals, and then printing the second to last token. I thought "awk" could help me, but I don't know how to say "second to last". This doesn't cut it

awk '{print $2=$3}' /tmp/country_data.tsv 

How can I extract the data in the way I want?

1
source | link

How do I tell awk I want the second to last and third to last tokens from a tab-delimited line?

I'm using a bash script. I have a tab delimited file with data that looks like

Afghanistan     AF      AFG     004
ALA     Aland Islands   AX      ALA     248
Albania AL      ALB     008
Algeria DZ      DZA     012

I want to rewrite the data like so

AF=AFG
AX=ALA
AL=ALB
DZ=DZA

which boils down to extracting the third to last token, writing an equals, and then printing the second to last token. I thought "awk" could help me, but I don't know how to say "second to last". This doesn't cut it

awk '{print $2=$3}' /tmp/country_data.tsv 

How can I extract the data in the way I want?