我正在尝试从多个文件中删除重复的 if block ,例如 returnString() 内的 if block 存在于许多其他文件中:
/**
*
*
*Some text
*
*/
private String returnString() {
if (containsString()) {
System.out.println("Random text");
System.out.println("Random text");
}
System.out.println("Random text");
}
Some text
Some text
我已将这些数据存储在一个文件中,我想使用脚本从所有文件中删除整个 if block 。所以最终的输出应该是:
/**
*
*
*Some text
*
*/
private String returnString() {
System.out.println("Random text");
}
Some text
Some text
我以前没有任何脚本经验,但我尝试过 sed 并且能够删除一些行,但不能删除完整的 block 。请看看是否有人可以提供帮助。
最佳答案
使用 GNU sed:
sed -i '/if .* {/,/}/d' file
关于linux - 删除多行 block 的脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27671886/