我有一個auto_generated文件,可能會有重複的數據,這會導致我的解析器崩潰。我該如何逐行檢查並根據它在bash上具有的字符刪除不需要的行?例如:如何複製或刪除bash中的特定行並將它們創建爲新文件
for line in file.txt:
if '(1)' in line:
delete line
elif '(2)' in line:
delete line
elif '(3)' in line:
delete line
else:
return (file.txt with those lines removed)
採樣輸入
Hello my name is john
Hello my name is eric
Hello my name is jonh(2)
Hello my name is ray
Hello my name is john (1)
Hello my name is eric (3)
樣本輸出
Hello my name is john
Hello my name is eric
Hello my name is ray
請爲樣本輸入添加樣本輸入和您想要的輸出到您的問題。 – Cyrus
你嘗試過'grep -v'嗎? – chrisaycock