Hi,
Using awk:
Code:
#!/bin/bash
awk '
BEGIN {
# load array with contens f1.txt
while ( getline < "f1.txt" > 0 )
{
f1_counter++
f1[f1_counter] = $1
}
}
{
print $1, $2, f1[NR], $3
} ' f2.txt
In the BEGIN part all content of f1.txt is loaded into an array. The correct array entry can be printed by using the NR variable that holds the current record value. So
print $1, $2, f1[NR], $3 first prints fields 1 and 2 from f2.txt, then f1[NR], which is the corresponding entry from f1.txt. Last the third field from f2.txt is printed.
cat f1.txt
F1column1
F1column1
F1column1
F1column1
F1column1
cat f2.txt
f2column1 f2column2 f2column3
f2column1 f2column2 f2column3
f2column1 f2column2 f2column3
f2column1 f2column2 f2column3
f2column1 f2column2 f2column3
Output above script:
f2column1 f2column2 F1column1 f2column3
f2column1 f2column2 F1column1 f2column3
f2column1 f2column2 F1column1 f2column3
f2column1 f2column2 F1column1 f2column3
f2column1 f2column2 F1column1 f2column3
Hope this helps.