Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex Unix shell脚本:在“输入”时插入文本;“文本模式”;找到_Regex_Shell_Unix_Cat - Fatal编程技术网

Regex Unix shell脚本:在“输入”时插入文本;“文本模式”;找到

Regex Unix shell脚本:在“输入”时插入文本;“文本模式”;找到,regex,shell,unix,cat,Regex,Shell,Unix,Cat,假设我有两个文件: -data.txt -report.txt 报告包含带有一些“占位符”的文本,例如: HPLC results for sample: <insert-sample-id-here>, elements analyzed: <insert-element-name> 这里不是计算机高手,但我知道“查找和替换”的任务可以由计算机自动完成;“用我的数据文件中匹配对的值替换占位符后,应使用何种命令重写report.txt?”在当前的文件格式中,很难将数据文

假设我有两个文件: -data.txt -report.txt

报告包含带有一些“占位符”的文本,例如:

HPLC results for sample: <insert-sample-id-here>, elements analyzed: <insert-element-name>

这里不是计算机高手,但我知道“查找和替换”的任务可以由计算机自动完成;“用我的数据文件中匹配对的值替换占位符后,应使用何种命令重写report.txt?”

在当前的文件格式中,很难将数据文件中的值与报告文件中的占位符匹配,因为占位符
与data.txt中的
sampleID
不同。
elementName
不相同

但假设您有不同形式的
data.txt

insert-sample-id-here: 123456abc
insert-element-name: genericThickeningAgent
(因此,如果
data.txt
中的键与
report.txt
中的占位符匹配),可以使用以下命令:

$ perl -ne 'print "s/<$1>/$2/g\n" if /^(.*?):\s+(.*)$/' data.txt | \
    xargs -I% perl -p -i -w -e "%" report.txt

哇,这真是超出了我的要求!我认为有必要为每一对写下“查找和替换”。我看看是否可以更改报告模板。非常感谢您的解决方案,太好了!
$ perl -ne 'print "s/<$1>/$2/g\n" if /^(.*?):\s+(.*)$/' data.txt | \
    xargs -I% perl -p -i -w -e "%" report.txt
$ cat report.txt
results for sample: 123456abc, elements analyzed: genericThickeningAgent