I have a list like this
G1 John
G2 Jack
G3 Ray
G4 Tim
and a second list in another file
Jack John
Tim Jack
I want to write a bash code that gives me a third file like this
G2 G1
G4 G2
EDIT My solution is this, but nothing happens when I write it in bash.
#! /bin/bash
INPUTFILE="id.tsv"
DATAFILE="g.tsv"
OUTFILE="output.csv"
awk 'BEGIN {
while (getline < "'"$INPUTFILE"'")
{
split($0,ft,"\t");
id=ft[1];
name=ft[2];
key=id;
data=name;
nameArr[key]=data;
}
close("'"$INPUTFILE"'");
while (getline < "'"$DATAFILE"'")
{
split($0,ft,",");
id1=ft[1]; # Id is the first column
id2=ft[2]; # Phonenumber is the second
name1=nameArr[id1];
name2=nameArr[id2];
print name1","name2 > "'"$OUTFILE"'"; # Print directly to the outputfile
}
}'