У меня есть файл, содержащий какой-то текст и какой-то placeHolder, а другой файл с другим текстом
Например: myText.txt:
some text strings plus a {{myPlaceholderText}} and some more text
myPlaceholderText.txt:
more text here
Я хочу иметь возможность создать третий файл, содержащий строку:
"some text strings plus a more text here and some more text"
Можно ли это сделать с помощью инструментов командной строки?
Я думаю, что sed - это самый простой способ сделать это:
$ sed "s/{{myPlaceholderText}}/$(<myPlaceholder.txt)/g" myText.txt
some text strings plus a more text here and some more text
Да. И bash - самый безопасный общий инструмент, помимо интерпретируемых языков.
#!/bin/bash
R=$(<myPlaceholderText.txt)
while read -r LINE; do
echo "${LINE//'{{myPlaceholderText}}'/$R}"
done < myText.txt > another_file.txt
Вывод в файл another_file.txt:
some text strings plus a more text here and some more text
Другой через awk:
awk 'BEGIN{getline r < ARGV[1];ARGV[1]=""}{gsub(/{{myPlaceholderText}}/,r)}1' myPlaceholderText.txt myText.txt > another_file.txt