Skip to main content
deleted 138 characters in body
Source Link
jimmij
  • 48.7k
  • 20
  • 136
  • 141

If words in file2 are unique then you can reverse the order of the files, build an array from file2 and apply it to file1:

$ awk 'NR==FNR{a[$1]=$2;next}{print $1,a[$2]}' file2 file1
word_1 root_of_word_1
word_2 root_of_word_2
word_3 root_of_word_3
word_4 root_of_word_1

(Obviously you can redirect the output to another file from within the awk, but redirection part of your question is not clear to me).

If words in file2 are unique then you can reverse the order of the files, build an array from file2 and apply it to file1:

$ awk 'NR==FNR{a[$1]=$2;next}{print $1,a[$2]}' file2 file1
word_1 root_of_word_1
word_2 root_of_word_2
word_3 root_of_word_3
word_4 root_of_word_1

(Obviously you can redirect the output to another file from within the awk, but redirection part of your question is not clear to me).

If words in file2 are unique then you can reverse the order of the files, build an array from file2 and apply it to file1:

$ awk 'NR==FNR{a[$1]=$2;next}{print $1,a[$2]}' file2 file1
word_1 root_of_word_1
word_2 root_of_word_2
word_3 root_of_word_3
word_4 root_of_word_1
Source Link
jimmij
  • 48.7k
  • 20
  • 136
  • 141

If words in file2 are unique then you can reverse the order of the files, build an array from file2 and apply it to file1:

$ awk 'NR==FNR{a[$1]=$2;next}{print $1,a[$2]}' file2 file1
word_1 root_of_word_1
word_2 root_of_word_2
word_3 root_of_word_3
word_4 root_of_word_1

(Obviously you can redirect the output to another file from within the awk, but redirection part of your question is not clear to me).