您的位置:首页 > 运维架构 > Linux

linux删除文件中含有某字符的行

2014-01-09 13:50 295 查看
sed -i -e '/string/d' file

脚本,从键盘输入删除含某字符行

#!/bin/sh
FILENAME=file.txt   # 可换为$1

if [ ! -f file.txt ];then
        echo "$FILENAME no found"
        exit 1
fi
echo -n "INPUT SOME THING: "
read
if [ ! -z "$REPLY" ];then
     INFO=$(grep $REPLY FILENAME)
     if [ ! -z "$INFO" ] ; then
          sed -i -e '/$REPLY/d' FILENAME   #删除只用这行就可以了
     else
          echo "没有指定内容的信息"
          exit 1
     fi
else 
     echo "input some thing"
     exit 1
fi
exit $?
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: