使用带有 --summarize
标志的 svn diff
返回类似下面的内容。我们如何将其传递给 sed 或 grep 以执行以下操作:
- 删除所有以“D”开头的行(删除的文件)
- 删除“M”、“A”或“MM”(或任何其他情况)的前缀以及之后的标签。
- 删除 URL 路径,仅保留文件名/文件夹。
- 保存在文件中
例子:
D https://localhost/example/test1.php
D https://localhost/example/test2.php
M https://localhost/example/test3.php
M https://localhost/example/test4.php
A https://localhost/example/test5.php
M https://localhost/example/test6.php
A https://localhost/example/test7.php
M https://localhost/example/test8.php
M https://localhost/example/test9.php
M https://localhost/example/test10.php
A https://localhost/example/test11.php
M https://localhost/example/test12.php
M https://localhost/example/test13.php
MM https://localhost/example/test.php
M https://localhost/test0.php
然后会变成:
/example/test3.php
/example/test4.php
/example/test5.php
/example/test6.php
/example/test7.php
/example/test8.php
/example/test9.php
/example/test10.php
/example/test11.php
/example/test12.php
/example/test13.php
/example/test.php
/test0.php
最佳答案
像这样使用 sed
:
$ svn diff --summarize | sed -e '/^D/d' -e 's/.*host//'
/example/test3.php
/example/test4.php
/example/test5.php
/example/test6.php
/example/test7.php
/example/test8.php
/example/test9.php
/example/test10.php
/example/test11.php
/example/test12.php
/example/test13.php
/example/test.php
/test0.php
# Redirect output to file
$ svn diff --summarize | sed -e '/^D/d' -e 's/.*host//' > file
您需要pipe |
svn
到 sed
的输出。第一部分 '/^D/d'
删除所有以 D
开头的行,第二部分 s/.*host//
替换所有内容直到 host
什么都没有,要存储到文件中使用 redirect >文件
。
与grep
类似的逻辑:
$ svn diff --summarize | grep '^[^D]' file | grep -Po '(?<=host).*' > file
第一个 grep
过滤掉以 D
开头的行,第二个使用 positive lookahead使用 -Po
只显示 host
之后的部分行。
关于linux - 如何解析 svn diff 结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14176503/