将svn diff
与--summarize
标志一起使用会返回如下所示的内容。我们如何将它传递给sed或grep以执行以下操作:
示例:
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
答案 0 :(得分:1)
与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
,无任何内容,以存储到文件中使用{{3} } > file
。
与grep
类似的逻辑:
$ svn diff --summarize | grep '^[^D]' file | grep -Po '(?<=host).*' > file
第一个grep
过滤掉以D
开头的行,第二个redirect过滤-Po
以仅显示host
之后的行部分}。