当前位置:网站首页>Shell-sed命令的使用
Shell-sed命令的使用
2022-04-23 17:04:00 【魔笛Love】
sed
sed是一种流编辑器,它一次处理一行内容。处理时,把当前处理的行存储在临时缓冲区中,称为“模式空间”,接着用sed命令处理缓冲区中的内容,处理完成后,把缓冲区的内容送往屏幕。接着处理下一行,这样不断重复,直到文件末尾。文件内容并没有改变,除非你使用重定向存储输出。
基本用法
sed [选项参数] 'command' filename
选项参数说明
选项参数 | 功能 |
---|---|
-e | 直接在指令列模式上进行sed的动作编辑。 |
常用命令功能描述
命令 | 功能描述 |
---|---|
a | 新增,a的后面可以接字串,在下一行出现 |
d | 删除 |
s | 查找并替换 |
案例实操
# 数据准备
[bd@localServer ~]$ touch sed.txt
[bd@localServer ~]$ vim sed.txt
fu xia
zhou men
wo wo
lai lai
le le
### 将“wo shi”这个单词插入到sed.txt第二行下,打印。
[bd@localServer ~]$ sed '2a wo shi' sed.txt
fu xia
zhou men
wo shi
wo wo
lai lai
le le
#### 源文件没有改变
[bd@localServer ~]$ cat sed.txt
fu xia
zhou men
wo wo
lai lai
le le
### 删除sed.txt文件所有包含wo的行
[bd@localServer ~]$ sed '/wo/d' sed.txt
fu xia
zhou men
lai lai
le le
### 将sed.txt文件中wo替换为ni,g表示global为全局操作,不加的话只处理第一个
[bd@localServer ~]$ sed 's/wo/ni/g' sed.txt
fu xia
zhou men
ni ni
lai lai
le le
### 将sed.txt文件中的第二行删除并将wo替换为ni
[bd@localServer ~]$ sed -e '2d' -e 's/wo/ni/g' sed.txt
fu xia
ni ni
lai lai
le le
版权声明
本文为[魔笛Love]所创,转载请带上原文链接,感谢
https://blog.csdn.net/clearlxj/article/details/121742569
边栏推荐
- ACL 2022 | DialogVED:用于对话回复生成的预训练隐变量编码-解码模型
- [PROJECT] small hat takeout (8)
- Mock test
- Feign report 400 processing
- Go language, array, string, slice
- MySQL master-slave replication
- VLAN高级技术,VLAN聚合,超级Super VLAN ,Sub VLAN
- 线性代数感悟之1
- [problem solving] [show2012] random tree
- Some problems encountered in recent programming 2021 / 9 / 8
猜你喜欢
How much do you know about the process of the interview
网络安全之渗透靶场实战详解
ByteVCharts可视化图表库,你想要的我都有
PyMySQL
TypeError: set_ figure_ params() got an unexpected keyword argument ‘figsize‘
On lambda powertools typescript
Grpc gateway based on Ocelot
RTKLIB 2.4.3源码笔记
Detailed explanation of information abstract, digital signature, digital certificate, symmetric encryption and asymmetric encryption
The new MySQL table has a self increasing ID of 20 bits. The reason is
随机推荐
Go language RPC communication
JSON deserialize anonymous array / object
STM32__ 03 - beginner timer
Handwritten event publish subscribe framework
Camtasia2022软件新增功能介绍
◰GL-着色器处理程序封装
1-4 configuration executable script of nodejs installation
Grpc gateway based on Ocelot
Mock test using postman
Do you really understand the principle of code scanning login?
Nacos + aspnetcore + Ocelot actual combat code
Summary of common websites
On lambda powertools typescript
Bottom processing of stack memory in browser
Copy constructor shallow copy and deep copy
Detailed explanation of the penetration of network security in the shooting range
[problem solving] [show2012] random tree
Sub database and sub table & shardingsphere
1-2 JSX syntax rules
Aiot industrial technology panoramic structure - Digital Architecture Design (8)