bash删除文件中含指定内容的行
生活随笔
收集整理的這篇文章主要介紹了
bash删除文件中含指定内容的行
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
#!/bin/sh
# 功能: 刪除文件中含"指定內容"的行
# 運行方式: ./dline.sh c.log ==> 產生輸出文件: c.log0array=("rm -f lvr_3531_pf_new""arm-hisiv100-linux-gcc ""In function ""excess elements in array initializer""warning: multi-line comment""embedded '\\0' in format""__NR_SYSCALL_BASE""this is the location of the previous definition""dereferencing type-punned pointer will break strict-aliasing rules""differ in signedness""but argument is of type""implicit declaration of"
)if [ $# -lt 1 ]; thenecho "Usage: $0 <logfile>"exit
fifile="$1"0
cp -f $1 $filefunction deleteLine()
{sed "/$1/d" $file > tmpmv -f tmp $file
}wc -l $filefor line in "${array[@]}"
doif [ ${#line} -gt 0 ] && [ ${line:0:1} != "#" ]; thendeleteLine "$line"fi
donewc -l $file
運行情況:
[feng@bash #69]$./dline.sh c.log
556 c.log0
63 c.log0
[feng@bash #70]$
總結
以上是生活随笔為你收集整理的bash删除文件中含指定内容的行的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【计算机技术】我用两句话在电脑课上解除了
- 下一篇: 《数据科学R语言实践:面向计算推理与问题