Linux bash刪除文件中含“指定內(nèi)容”的行功能示例
更新時(shí)間:2017年06月09日 09:16:21 作者:JoeBlackzqq
這篇文章主要介紹了Linux bash刪除文件中含“指定內(nèi)容”的行功能,結(jié)合具體實(shí)例形式分析了Linux bash刪除文件指定內(nèi)容的實(shí)現(xiàn)原理與相關(guān)操作技巧,需要的朋友可以參考下
本文實(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)文章
Python執(zhí)行Linux系統(tǒng)命令的4種方法
這篇文章主要介紹了Python執(zhí)行Linux系統(tǒng)命令的4種方法,即在Python腳本中調(diào)用Shell命令,需要的朋友可以參考下2014-10-10解決linux?shell中傳遞包含空格的參數(shù)問(wèn)題
這篇文章主要介紹了如何解決linux?shell中傳遞包含空格的參數(shù)問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-09-09shell腳本執(zhí)行命令自動(dòng)填充密碼(自動(dòng)輸入密碼)
這篇文章主要介紹了shell?執(zhí)行命令自動(dòng)填充密碼,文中結(jié)合實(shí)例代碼通過(guò)三種方式講解了Shell?腳本自動(dòng)輸入密碼的方法,需要的朋友可以參考下2023-02-02Linux的打包壓縮與解壓縮---tar、xz、zip、unzip命令詳解
Linux 下一堆各式各樣的壓縮文件名:.gz、.tar.gz、tgz、bz2、.Z、.tar 等眾多的壓縮文件名,本文重點(diǎn)介紹Linux的打包壓縮與解壓縮---tar、xz、zip、unzip命令,感興趣的朋友一起看看吧2024-02-02