Это будет работать с любым awk в любой оболочке на каждом поле UNIX с учетом ввода, как в вашем примере:
awk '
match($0,/\{\{.*}}/) {
fname = substr($0,RSTART+2,RLENGTH-4)
while ( (getline < fname) > 0 ) {
print
}
close(fname)
next
}
{ print }
' file
например,
$ cat tam
When chapman billies leave the street,
And drouthy neebors neebors meet,
As market-days are wearing late,
{{foo}}
We think na on the lang Scots miles,
The mosses, waters, slaps, and stiles,
{{bar}}
Gathering her brows like gathering storm,
Nursing her wrath to keep it warm.
$ cat foo
And folk begin to tak the gate;
While we sit bousin, at the nappy,
And gettin fou and unco happy,
$ cat bar
That lie between us and our hame,
Whare sits our sulky, sullen dame,
.
awk '
match($0,/\{\{.*}}/) {
fname = substr($0,RSTART+2,RLENGTH-4)
while ( (getline < fname) > 0 ) {
print
}
close(fname)
next
}
{ print }
' tam
When chapman billies leave the street,
And drouthy neebors neebors meet,
As market-days are wearing late,
And folk begin to tak the gate;
While we sit bousin, at the nappy,
And gettin fou and unco happy,
We think na on the lang Scots miles,
The mosses, waters, slaps, and stiles,
That lie between us and our hame,
Whare sits our sulky, sullen dame,
Gathering her brows like gathering storm,
Nursing her wrath to keep it warm.
Образец ввода любезно предоставлен Рабб ie Ожоги .