In a folder collection, I have following files:fberry.txt   lberry.txtfgag.txt     lgag.txtfred.txt     lred.txtftea.txt     ltea.txtfluck.txt    lluck.txtWe can find that these files can be divided into two types: one begins with f, and the other begins with l. And every two files share a same name (except the first letter), for example: In fberry.txt and lberry.txt, berry.txt is the same. In these two paired files, the first column of each file is the same, I want to merge these two files (the first two columns of lberry.txt and the third column of fberry.txt) based on the same column.I use following code:cd ~/collectionawk 'NR==FNR {h[$1]=$3; next} {print $1,$2,h[$1]}' fberry.txt lberry.txt > tberry.txtIt can produce the result I want, but I don't know how to handle all these paired files together, otherwise, I need to write 5 codes like this, and if there are 100+ files, it will be a disaster. My expected result is to get 5 new files: tberry.txt,tgag.txt,tred.txt,ttea.txt and tluck.txt.Thanks.
How to handle a series of paired files
bash;shell script;awk
for file in f*.txtdo name=${file:1}awk 'NR==FNR {h[$1]=$3; next} {print $1,$2,h[$1]}' $file l$name > t$namedoneThanks to @don_crissti. Here, ${file:1} can extract the characters after the first character. With this, I can easily get the common part of paired filenames. The syntax of ${file:1} is ${string: index: length}.