我经历了其他与我相似的问题。 以下命令有效,但是如果我尝试删除除具有字符串“ .c”或“ .h”的行以外的所有行,则该命令不起作用。
sed -r -n -e '/.java|.c/p' test.txt
/home/jenkins/workspace/Test/base/src/packages/.c
/home/jenkins/workspace/Test/base/src/packages/.txt
/home/jenkins/workspace/Test/base/packages/Manager.java
答案 0 :(得分:2)
使用GNU sed:
List<int> testList = new List<int>{1,76,3,4,5,76,76,8};
public void RemoveElements()
{
for (int i = testList.Count - 1; i >= 0; i--)
{
// RemoveAt option
if(testList[i] == 76) testList.RemoveAt(i);
}
}
或
sed -n '/\.c\|\.h/p' file
或
sed -n -E '/\.c|\.h/p' file