【发布时间】:2018-07-08 00:07:46
【问题描述】:
我有一个文本文件info.txt,其中包含:
/* prog_dir=/path/to/some/directory; */
dir_1=/some/other/path/to/a/directory/first;
dir_2=/some/other/path/to/a/directory/secord;
在这里,我想替换这两对字符串之间存在的字符串,例如dir_1=/some/other/path/to/a/directory/ 和 ; AND dir_2=/some/other/path/to/a/directory/ 和 ; 和 R03_0 用于所有行 info.txt 文件。
对于每一行,它都应该应用替换。
转换后,info.txt 文件应该是这样的:
/* prog_dir=/path/to/some/directory; */
dir_1=/some/other/path/to/a/directory/R03_0;
dir_2=/some/other/path/to/a/directory/R03_0;
试过这个:
sed '/^dir_1=/some\/other\/path\/to\/a\/directory\//,/^;/R03_0' /path/to/the/text/file/info.txt
如果我们可以将替换脚本R03_0 作为变量$rel_ver 传递给sed/awk 命令会更好。
有什么建议吗?
【问题讨论】:
-
所有行的目录路径都一样吗?