Reputation: 35
I have a very long list of words (with duplications) like this:
list1.txt
Apple
Pear
Banana
Banana
Banana
Banana
Orange
Orange
I want to replace every words in the list1.txt with another list of words (with no duplications), list2.txt, that contains the same words of the list1.txt plus something more:
list2.txt
Apple_red
Pear_green
Banana_yellow
Orange_orange
I need an output like this:
list3.txt
Apple_red
Pear_green
Banana_yellow
Banana_yellow
Banana_yellow
Banana_yellow
Orange_orange
Orange_orange
Any suggestions? Thank you!
Upvotes: 0
Views: 56
Reputation: 785246
You may use this awk
:
awk -F'_' 'NR==FNR{a[$1]=$0; next} {print a[$1]}' list2.txt list1.txt
Apple_red
Pear_green
Banana_yellow
Banana_yellow
Banana_yellow
Banana_yellow
Orange_orange
Orange_orange
Upvotes: 1
Reputation: 58430
This might work for you:
uniq list1.txt | paste -d/ - list2.txt | sed 's#.*#s/&/#' | sed -f - list1.txt
/
as separator.Upvotes: 0