Linux bash删除文件中含“指定内容”的行功能示例
本文实例讲述了Linuxbash删除文件中含“指定内容”的行功能。分享给大家供大家参考,具体如下:
#!/bin/sh #功能:删除文件中含"指定内容"的行 #运行方式:./dline.shc.log==>产生输出文件:c.log0 array=( "rm-flvr_3531_pf_new" "arm-hisiv100-linux-gcc" "Infunction" "excesselementsinarrayinitializer" "warning:multi-linecomment" "embedded'\\0'informat" "__NR_SYSCALL_BASE" "thisisthelocationofthepreviousdefinition" "dereferencingtype-punnedpointerwillbreakstrict-aliasingrules" "differinsignedness" "butargumentisoftype" "implicitdeclarationof" ) if[$#-lt1];then echo"Usage:$0" exit fi file="$1"0 cp-f$1$file functiondeleteLine() { sed"/$1/d"$file>tmp mv-ftmp$file } wc-l$file forlinein"${array[@]}" do if[${#line}-gt0]&&[${line:0:1}!="#"];then deleteLine"$line" fi done wc-l$file
运行情况:
[feng@bash#69]$./dline.shc.log 556c.log0 63c.log0 [feng@bash#70]$
希望本文所述对大家bashshell学习有所帮助。
热门推荐
1 训练狗狗憋尿
2 狗狗追踪训练
3 狗狗训练要多少钱
5 深圳狗狗训练
6 训练狗狗唤回
7 狗狗叫怎么训练
8 狗狗训练班
10 狗狗社会化训练
11 狗狗叫回训练
12 广州狗狗训练学校
13 狗狗训练躺下
14 狗狗随行训练
15 训练狗狗巡回
16 狗狗要怎么训练
17 狗狗喂食训练
18 训练狗狗躺下