Linux bash删除文件中含“指定内容”的行功能示例
本文实例讲述了Linux bash删除文件中含“指定内容”的行功能。分享给大家供大家参考,具体如下:
#!/bin/sh # 功能: 删除文件中含"指定内容"的行 # 运行方式: ./dline.sh c.log ==> 产生输出文件: 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
运行情况:
[feng@bash #69]$./dline.sh c.log 556 c.log0 63 c.log0 [feng@bash #70]$
希望本文所述对大家bash shell学习有所帮助。
Vim中列出TODO与FIXME等备注的方法
前言很多程序员,包括我,会在写代码的时候,习惯性的用TODO,FIXME,HACK等作为一些注释的前缀。这样方便自己和后来者预先知道相关注释和代码的状况
基于shell的if和else详解
基本语法shell的if语法和C语言等高级语言非常相似,唯一需要注意的地方就是shell的if语句对空格方面的要求比较严格(其实shell对所有语法的空格使用都
详解git无法pull仓库refusing to merge unrelated histories
详解git无法pull仓库refusingtomergeunrelatedhistories本文讲的是把Git在最新2.9.2,合并pull两个不同的项目,出现的问题如何去解决fatal:refusingtomergeunrelatedhistories
编辑:一起学习网
标签:语法,详解,本文,文件,空格