我想刪除文件中包含單詞「test」的所有行,但如果該行包含「test @」,那麼我不想刪除它。刪除文件中匹配一個字符串但不匹配另一個字符串的行 - SED,BASH?
可能有一些這樣做與sed的時髦的方式,但我掙扎,我試圖用sed寫一個bash循環,但這可能是愚蠢的。
filetest=/tmp/filetest
filetest_tmp=/tmp/filetest.tmp<
line_num=0
while read line; do
line_num=$(($line_num+1))
if [[ $line == *rootsh* ]] && [[ $line != *[email protected]* ]]
then
sed -e "${line_num}"'d' $filetest >> $filetest_tmp
fi
done < $filetest
cp $syslog_tmp $filetest
正如你所知道的,我在這個對於新手:(
請不要在您的示例中使用「root」時在描述中使用「test」。請在示例中使用「testsh」/「test @」時,不要在描述中使用「test」/「test @」。撰寫問題時請小心。請? – hop