访问手机版  

Linux常用命令|Linux培训学习|考试认证|工资待遇与招聘,认准超级网工!

招聘|合作 登陆|注册

网络工程师培训

当前位置:网络工程师 > 技术课程 > linux > 热点关注 > linux常用命令

Linux常用基本命令:三剑客命令之

时间:2019-11-21

常用dos命令大全_linux常用命令_linux命令vi进入后命令

sed是一个很强大的文件处理工具,主要是以行为单位进行处理,可以将数据行进行替换、删除、新增、选取等特定工作

格式:sed [option] [command] [file]

常用命令:

a ∶新增

c ∶取代

d ∶删除

i ∶插入

常用dos命令大全_linux命令vi进入后命令_linux常用命令

p∶列印

s∶取代

选项:

-i∶直接修改读取的档案内容,而不是由萤幕输出。

-n∶使用安静(silent)模式。在一般 sed 的用法中,所有来自 STDIN的资料一般都会被列出到萤幕上。但如果加上 -n 参数后,则只有经过sed 特殊处理的那一行(或者动作)才会被列出来。

1,sed '1d' ghostwu.com d代表删除 d前面的数字代表删除第一行,该命令不会修改文件本身

ghostwu@dev:~/linux/sed$ cat -n ghostwu.txt 
     1    this is ghostwu
     2    how are you
     3    hod old are you
     4    and you
     5    fine thank you
     6    come with me!!!
ghostwu@dev:~/linux/sed$ sed '1d' ghostwu.txt 
how are you
hod old are you
and you
fine thank you
come with me!!!
ghostwu@dev:~/linux/sed$ cat ghostwu.txt 
this is ghostwu
how are you
hod old are you
and you
fine thank you
come with me!!!

linux常用命令_常用dos命令大全_linux命令vi进入后命令

2,删除最后一行,$代表最后一行

ghostwu@dev:~/linux/sed$ cat ghostwu.txt 
this is ghostwu
how are you
hod old are you
and you
fine thank you
come with me!!!
ghostwu@dev:~/linux/sed$ sed '$d' ghostwu.txt 
this is ghostwu
how are you
hod old are you
and you
fine thank you

3,删除第一行到第二行

ghostwu@dev:~/linux/sed$ cat ghostwu.txt 
this is ghostwu
how are you
hod old are you
and you
fine thank you
come with me!!!
ghostwu@dev:~/linux/sed$ sed '1,2d' ghostwu.txt 
hod old are you
and you
fine thank you
come with me!!!

4,删除第二行到最后一行

ghostwu@dev:~/linux/sed$ sed '2,$d' ghostwu.txt 
this is ghostwu

5,查找包含'you'的行,/you/ 这是正则表达式, p是打印,要跟n结合起来用

linux命令vi进入后命令_linux常用命令_常用dos命令大全

ghostwu@dev:~/linux/sed$ cat ghostwu.txt 
this is ghostwu
how are you
hod old are you
and you
fine thank you
come with me!!!
ghostwu@dev:~/linux/sed$ sed -n '/you/p' ghostwu.txt 
how are you
hod old are you
and you
fine thank you
 上一个教程:整理一下Linux常用命令