Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/17.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 使用GREP或SED并使用unix命令行将文本字符串从一个字符串复制到另一个字符串_Bash_Shell_Unix_Sed_Grep - Fatal编程技术网

Bash 使用GREP或SED并使用unix命令行将文本字符串从一个字符串复制到另一个字符串

Bash 使用GREP或SED并使用unix命令行将文本字符串从一个字符串复制到另一个字符串,bash,shell,unix,sed,grep,Bash,Shell,Unix,Sed,Grep,我不熟悉命令行脚本。我只想复制从一个特定字符串开始并以另一个字符串结尾的文本。我如何使用sed、grep或任何其他方式实现这一点 例如: 在这里,我想从保存到log.txt的错误日志中复制----CompilerOutput:-stderr----到----EndCompilerOutput----的文本 提前感谢。以下简单的sed可能也会对您有所帮助 sed -n '/CompilerOutput:-stderr/,/EndCompilerOutput/p' Input_file 说明:在此

我不熟悉命令行脚本。我只想复制从一个特定字符串开始并以另一个字符串结尾的文本。我如何使用sed、grep或任何其他方式实现这一点

例如:

在这里,我想从保存到
log.txt的错误日志中复制
----CompilerOutput:-stderr----
----EndCompilerOutput----
的文本


提前感谢。

以下简单的
sed
可能也会对您有所帮助

sed -n '/CompilerOutput:-stderr/,/EndCompilerOutput/p' Input_file

说明:在此处使用
sed
-n
选项,默认情况下将停止打印行。然后通过执行
/CompilerOutput:-stderr/,/EndCompilerOutput/
这一操作,我正在从string
/CompilerOutput:-stderr
EndCompilerOutput
的行上搜索字符串。如果此条件为真,则使用
p
选项将打印这些行。

sed-n'/pattern1/,/pattern2/p'文件
很好,可以正常工作。thanks@RavinderSingh13:关于这一性质,有很多类似的问题!“你为什么要回答一个已知的骗局?”伊尼安,抱歉,我没有搜索它。
sed -n '/CompilerOutput:-stderr/,/EndCompilerOutput/p' Input_file