Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/google-chrome/4.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
Bash 用前一行的内容替换文本_Bash - Fatal编程技术网

Bash 用前一行的内容替换文本

Bash 用前一行的内容替换文本,bash,Bash,我有一个文本文件,其中包含以下类型的多个块 我想用一个工具的输出替换“replaceme”,该工具将“somewordcode1”作为输入(以及“someotherwordcode2”等)。 我可以将该输出放在变量中(如果需要,也可以放在数组中)。 它应该在bash中完成 有什么建议吗 Tag: CODE1 (1) *This: someword CODE1 Some message that may contain all kinds of characters /p

我有一个文本文件,其中包含以下类型的多个块

我想用一个工具的输出替换“replaceme”,该工具将“somewordcode1”作为输入(以及“someotherwordcode2”等)。 我可以将该输出放在变量中(如果需要,也可以放在数组中)。 它应该在bash中完成

有什么建议吗

Tag: CODE1 (1)
  *This: someword CODE1
    Some message that may contain all kinds of characters
       /path/to/file,143|25
replaceme
Tag: CODE2 (5)
  *That: someotherword CODE2
    Some other message that may contain all kinds of characters
       /path/to/anotherfile,110|30
replaceme

您正在尝试将“replaceme”替换为“可能包含各种字符的邮件”。我对这个问题的理解正确吗?你基本上是要求我们为你写一个脚本。也许你会幸运,但我们不是一个编码服务;我们通常不是那样工作的。在编写您想要的脚本时,您面临哪些具体问题?缩小你的问题范围,把重点放在这些方面。知道要记住哪些文本的标准是什么?是“Tag:”后面的那一行,还是“This:”或“That:”后面的文字?你看了
awk
及其
系统
功能了吗?对不起,我没有要求完整的脚本,不过如果有人帮我做的话我会很高兴:-)更多关于一般攻角的内容。我尝试过各种awk和sed命令,但我仍然坚持使用命令替换sed。例如,这是有效的:
sed“s | foo |$(pwd)| g”
但不是
sed“s | foo |$(mycommand)| g”