Linux bash刪除文件中含“指定內(nèi)容”的行功能示例
本文實(shí)例講述了Linux bash刪除文件中含“指定內(nèi)容”的行功能。分享給大家供大家參考,具體如下:
#!/bin/sh
# 功能: 刪除文件中含"指定內(nèi)容"的行
# 運(yùn)行方式: ./dline.sh c.log ==> 產(chǎn)生輸出文件: c.log0
array=(
"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 ]; then
echo "Usage: $0 <logfile>"
exit
fi
file="$1"0
cp -f $1 $file
function deleteLine()
{
sed "/$1/d" $file > tmp
mv -f tmp $file
}
wc -l $file
for line in "${array[@]}"
do
if [ ${#line} -gt 0 ] && [ ${line:0:1} != "#" ]; then
deleteLine "$line"
fi
done
wc -l $file
運(yùn)行情況:
[feng@bash #69]$./dline.sh c.log 556 c.log0 63 c.log0 [feng@bash #70]$
希望本文所述對(duì)大家bash shell學(xué)習(xí)有所幫助。
相關(guān)文章
Linux 使用shell腳本處理字符串的實(shí)現(xiàn)
這篇文章主要介紹了Linux 使用shell腳本處理字符串的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-12-12
shell腳本編寫ping包及arp的監(jiān)控并發(fā)送短信功能
這篇文章主要介紹了shell腳本編寫ping包及arp的監(jiān)控并發(fā)送短信功能,需要的朋友可以參考下2017-03-03
Shell腳本實(shí)現(xiàn)監(jiān)控rsync數(shù)據(jù)是否傳輸完
這篇文章主要介紹了Shell腳本實(shí)現(xiàn)監(jiān)控rsync數(shù)據(jù)是否傳輸完,本文直接給出實(shí)現(xiàn)代碼,需要的朋友可以參考下2014-12-12
linux下監(jiān)控網(wǎng)絡(luò)流量的腳本
在我們的日常工作當(dāng)中,監(jiān)控網(wǎng)絡(luò)要么使用iptarf,ifstat這些命令實(shí)現(xiàn)的,但是需要裝額外的RPM包。特別是iptarf裝起來麻煩2013-01-01
編寫shell腳本將VPS上的數(shù)據(jù)備份到Dropbox網(wǎng)盤的方法
這篇文章主要介紹了編寫shell腳本將VPS上的數(shù)據(jù)備份到Dropbox網(wǎng)盤的方法,注意Dropbox在國內(nèi)訪問的網(wǎng)絡(luò)相關(guān)問題,需要的朋友可以參考下2015-07-07
shell腳本學(xué)習(xí)指南[五](Arnold Robbins & Nelson H
這篇文章主要介紹了shell腳本學(xué)習(xí)指南[五](Arnold Robbins & Nelson H.F. Beebe著),需要的朋友可以參考下2014-02-02
linux設(shè)置定時(shí)任務(wù)的方法步驟
這篇文章主要介紹了linux設(shè)置定時(shí)任務(wù)的方法步驟,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2018-05-05
shell腳本實(shí)現(xiàn)磁盤監(jiān)控系統(tǒng)
這篇文章主要介紹了shell腳本實(shí)現(xiàn)磁盤監(jiān)控系統(tǒng),幫助大家更好的利用shell腳本管理數(shù)據(jù),感興趣的朋友可以了解下2020-09-09
Shell(())實(shí)現(xiàn)對(duì)整數(shù)進(jìn)行數(shù)學(xué)運(yùn)算
這篇文章主要介紹了Shell(())實(shí)現(xiàn)對(duì)整數(shù)進(jìn)行數(shù)學(xué)運(yùn)算,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-03-03

