shell中怎么删除文件中指定行的

shell中怎么删除文件中指定行的,第1张

1、删除包含指定关键字的行:

sed -i '/hello/d' test_temp 

[root@host]$ cat test_temp 

world

123

4566

889

2、删除指定行号的行

sed -i '2d' test_temp  

[root@host]$ cat test_temp        

world

4566

889

3、sed -i '1d' a.txt删首行

4、sed -i '$d' b.txt删尾行

5、sed -i 's/[ ]*//g' c.txt删空格

6、sed -i '/^$/d' d.txt删空行

7、sed -i ‘/love/d’ a.txt删包含string的行。

扩展资料:

shell 命令

常用命令:

cat 文件名 输出文件内容到基本输出(屏幕 or 加>fileName 到另一个文件)

cb 格式化源代码

chmod //change mode,改变文件的权限

cp copy

date 当前的时间和日期

echo $abc 在变量赋值之后,只需在变量前面加一个$去引用.

lint 语法检查程序

ls dir

man help

more type

du 查看磁盘空间状况

ps 查看当前进程状况

who 你的用户名和终端类型

定义变量 name=abc? (bash/pdksh) || set name = abc (tcsh)

mkdir 创建目录

rmdir 删除目录

cd 进入目录

rm 删除文件

more 显示文件

echo 显示指定文本

mv 改文件名 /移动文件

pwd 显示目录路径命令

参考资料来源:百度百科-shell

if test x"$1" = x"-f"then

    if test -f $2then

        rm -i $2

    else

        echo "$2 is not a regular file"

        exit 1

    fi

elif test x"$1" = x"-d" then

    if test -d $2then

        echo "are you sure delete directory(y\n) $2"

        read answer

        if test x"$answer"=="y"then

            rmdir $2

        fi

        exit 

    else

        echo "$2 is not a directory"

        exit 1

    fi

else

    echo "error parameters"

fi


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/tougao/12083917.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-20
下一篇2023-05-20

发表评论

登录后才能评论

评论列表(0条)

    保存