当前位置:网站首页>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
边栏推荐
- Basic case of Baidu map
- Path environment variable
- Generation of barcode and QR code
- SQL: How to parse Microsoft Transact-SQL Statements in C# and to match the column aliases of a view
- Milvus 2.0 质量保障系统详解
- Shell script -- shell programming specification and variables
- El date picker limits the selection range from the current time to two months ago
- Deeply understand the relevant knowledge of 3D model (modeling, material mapping, UV, normal), and the difference between displacement mapping, bump mapping and normal mapping
- An essay on the classical "tear down the wall in thinking"
- MySQL master-slave configuration under CentOS
猜你喜欢
1-4 configuration executable script of nodejs installation
Sub database and sub table & shardingsphere
Change the password after installing MySQL in Linux
Feign report 400 processing
Detailed explanation of information abstract, digital signature, digital certificate, symmetric encryption and asymmetric encryption
VLAN advanced technology, VLAN aggregation, super VLAN, sub VLAN
Mock test
博士申请 | 厦门大学信息学院郭诗辉老师团队招收全奖博士/博后/实习生
The new MySQL table has a self increasing ID of 20 bits. The reason is
Nodejs reads the local JSON file through require. Unexpected token / in JSON at position appears
随机推荐
ACL 2022 | DialogVED:用于对话回复生成的预训练隐变量编码-解码模型
Milvus 2.0 質量保障系統詳解
Generate random numbers with high quality and Gaussian distribution
Input file upload
Use between nodejs modules
Detailed explanation of Niuke - Gloves
Scope and scope chain in JS
Nacos + aspnetcore + Ocelot actual combat code
Further optimize Baidu map data visualization
Baidu Map Case - Zoom component, map scale component
Calculate pie chart percentage
VLAN advanced technology, VLAN aggregation, super VLAN, sub VLAN
线性代数感悟之2
Dancenn: overview of byte self-developed 100 billion scale file metadata storage system
Nodejs reads the local JSON file through require. Unexpected token / in JSON at position appears
Change the password after installing MySQL in Linux
杂文 谈谈古典的《拆掉思维里的墙》
Mock test using postman
[pimf] openharmony paper Club - what is the experience of wandering in ACM survey
Derivation of Σ GL perspective projection matrix