linux下删除指定的行

来源:岁月联盟 编辑:exp 时间:2012-05-07

linux下删除指定的行 #!/bin/shFILENAME=file.txt   # 可换为$1 if [ ! -f file.txt ];then        echo "$FILENAME no found"        exit 1  www.2cto.com  fiecho -n "INPUT SOME THING: "readif [ ! -z ”$REPLY“ ];then     INFO=$(grep $REPLY FILENAME)     if [ ! -z "$INFO" ] ; then          sed -i -e '/$REPLY/d' FILENAME   #删除只用这行就可以了     else          echo "没有指定内容的信息"          exit 1     fielse      echo "input some thing"     exit 1fiexit $?1. ============》》》添加        用sed在文档中间指定行后增加一行 有时候我们会用脚本,来修改文档,比如在文档中增加一行或减少一行echo "1";echo "2";echo "4";echo "5"; 如上例子,想要在echo "2";后面加上一条echo "3";可以用如下命令 sed -i '/echo /"2/";/a/echo /"3/";' test.sh 之所以用分号,是因为文本中本来就有。也就是说分号不是必须的! 抽象出来就是: sed -i '/* /a*' filename 2. ============》》》删除        sed 删除文件中的一行内容

http://topic.csdn.net/u/20080410/23/0c081d7c-85ab-4032-a536-d3bd8d55de8d.html Linux shell脚本 删除文件中的一行内容 比如:在1.txt里有以下内容:HELLO=1  www.2cto.com  NI=2WORLD=3I Love China.Love all.... 如果是要删除第三行:sed -i '3d' 1.txt 如果删除以Love开头的行sed -i '/^Love/d' 1.txt 删除包含Love的行sed -i '/Love/d' 1.txt   作者 gzh0222