Content #
读取命令还有一种很酷的用法是和删除命令配合使用,利用另一个文件中的数据来替换文件中的占位文本。假如你保存在文本文件中的套用信件如下所示: $ cat notice.std Would the following people: LIST please report to the ship’s captain. $ 套用信件将通用占位文本LIST放在了人物名单的位置。要在占位文本后插入名单,只需使用读取命令即可。但这样的话,占位文本仍然会留在输出中。为此,可以用删除命令删除占位文本,其结果如下: $ sed ‘/LIST/{ > r data12.txt > d > }’ notice.std Would the following people: Blum, R Browncoat McGuiness, A Alliance Bresnahan, C Browncoat Harken, C Alliance please report to the ship’s captain. $ 现在占位文本已经被替换成了数据文件中的名单。
From #
Linux命令行与shell脚本编程大全