Won*_*eal 5 unix linux bash sed sh
我想删除文件中包含"test"一词的所有行,但如果该行包含"test @",那么我不想删除它.
可能有一些时髦的方式用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 != *root@* ]]
then
sed -e "${line_num}"'d' $filetest >> $filetest_tmp
fi
done < $filetest
cp $syslog_tmp $filetest
Run Code Online (Sandbox Code Playgroud)
你可以告诉我,我是一个新手:(
Jon*_*ler 10
sed -e '/test/{/test@/!d;}'
Run Code Online (Sandbox Code Playgroud)
第一个模式匹配包含'test'的行; 第二种模式删除行,除非它们匹配'test @'.
测试数据文件:
aaaa
bbbtestbbb
ccctest@ccc
test!
dddd
Run Code Online (Sandbox Code Playgroud)
输出:
aaaa
ccctest@ccc
dddd
Run Code Online (Sandbox Code Playgroud)
这似乎符合您的要求.
归档时间: |
|
查看次数: |
6045 次 |
最近记录: |