当前位置:网站首页>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
边栏推荐
- Generate random numbers with high quality and Gaussian distribution
- 扫码登录的原理你真的了解吗?
- Further study of data visualization
- JS to find the character that appears three times in the string
- Aiot industrial technology panoramic structure - Digital Architecture Design (8)
- 1-2 characteristics of nodejs
- ◰GL-阴影贴图核心步骤
- Detailed explanation of Milvus 2.0 quality assurance system
- Baidu Map Case - Zoom component, map scale component
- Do you really understand the principle of code scanning login?
猜你喜欢
Idea of batch manufacturing test data, with source code
自定义my_strcpy与库strcpy【模拟实现字符串相关函数】
Shell script -- shell programming specification and variables
VLAN advanced technology, VLAN aggregation, super VLAN, sub VLAN
Nodejs reads the local JSON file through require. Unexpected token / in JSON at position appears
Milvus 2.0 détails du système d'assurance de la qualité
Modify the test case name generated by DDT
网络安全之渗透靶场实战详解
1-1 NodeJS
PyMySQL
随机推荐
Collect blog posts
Lock lock
蓝桥杯省一之路06——第十二届省赛真题第二场
websocket
vscode如何比较两个文件的异同
Detailed explanation of the penetration of network security in the shooting range
Milvus 2.0 détails du système d'assurance de la qualité
STM32__ 03 - beginner timer
VLAN高级技术,VLAN聚合,超级Super VLAN ,Sub VLAN
ACL 2022 | DialogVED:用于对话回复生成的预训练隐变量编码-解码模型
Calculation formula related to tolerance analysis
Detailed explanation of Milvus 2.0 quality assurance system
1-2 JSX syntax rules
Preliminary understanding of promse
Tencent resolves the address according to the IP address
SPC introduction
Further optimize Baidu map data visualization
Milvus 2.0 质量保障系统详解
Scope and scope chain in JS
SQL: How to parse Microsoft Transact-SQL Statements in C# and to match the column aliases of a view