2013-01-05 40 views
1

使用svn diff--summarize标志返回类似于下面的内容。我们如何将它传递给sed的或grep来做到以下几点:如何解析svn diff结果?

  1. 删除所有以“d”(删除文件)开始的任何行
  2. 删除的“M”前缀,“A”或“ MM“(或任何其他情况)以及随后的标签。
  3. 删除URL路径只留下文件名/文件夹。
  4. 存储在文件

例子:

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 
+2

您的输出结果与您的规格不符,它们不应包含'test1.php'或'test2.php',因为它们以'D'开头。 –

+0

谢谢,更新了我的示例输出以纠正错误。 – atdev

回答

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 

你的东东d至pipe|svnsed的输出。第一部分'/^D/d'删除所有以D开头的行,第二个s/.*host//将全部内容替换为host而没有任何内容,以存储到文件使用redirect> file

类似的逻辑与grep

$ svn diff --summarize | grep '^[^D]' file | grep -Po '(?<=host).*' > file 

第一grep筛选出与D开始的行和第二个使用与positive lookahead-Po只显示host后的线的一部分。