当前位置:网站首页>Use of shell sed command
Use of shell sed command
2022-04-23 17:06:00 【Magic Flute love】
sed
sed Is a flow editor , It processes one line at a time . When dealing with , Store the currently processed rows in a temporary buffer , be called “ Mode space ”, Then use sed Command processing buffer contents , After processing , Send the contents of the buffer to the screen . Next line , This is repeated , Until the end of the file . The contents of the document have not changed , Unless you use redirected storage output .
Basic usage
sed [ Option parameters ] 'command' filename
Option parameter description
Option parameters | function |
---|---|
-e | Directly in command line mode sed Action editor . |
Common command function description
command | Function description |
---|---|
a | newly added ,a You can use a string after , On the next line |
d | Delete |
s | Find and replace |
Case practice
# Data preparation
[bd@localServer ~]$ touch sed.txt
[bd@localServer ~]$ vim sed.txt
fu xia
zhou men
wo wo
lai lai
le le
### take “wo shi” This word is inserted into sed.txt Second elements , Print .
[bd@localServer ~]$ sed '2a wo shi' sed.txt
fu xia
zhou men
wo shi
wo wo
lai lai
le le
#### The source file has not changed
[bd@localServer ~]$ cat sed.txt
fu xia
zhou men
wo wo
lai lai
le le
### Delete sed.txt All files contain wo The line of
[bd@localServer ~]$ sed '/wo/d' sed.txt
fu xia
zhou men
lai lai
le le
### take sed.txt In file wo Replace with ni,g Express global For global operations , If not, only the first one
[bd@localServer ~]$ sed 's/wo/ni/g' sed.txt
fu xia
zhou men
ni ni
lai lai
le le
### take sed.txt The second line in the file is deleted and the wo Replace with ni
[bd@localServer ~]$ sed -e '2d' -e 's/wo/ni/g' sed.txt
fu xia
ni ni
lai lai
le le
版权声明
本文为[Magic Flute love]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231704450922.html
边栏推荐
- MySQL restores data through binlog file
- Detailed explanation of Niuke - Gloves
- Milvus 2.0 质量保障系统详解
- SQL database
- Customize my_ Strcpy and library strcpy [analog implementation of string related functions]
- Generation of barcode and QR code
- 网络安全之渗透靶场实战详解
- Scope and scope chain in JS
- Preliminary understanding of promse
- Shell-awk命令的使用
猜你喜欢
随机推荐
Read a blog, re understand closures and tidy up
The new MySQL table has a self increasing ID of 20 bits. The reason is
【WPF绑定3】 ListView基础绑定和数据模板绑定
Decimal format decimal / datetime conversion processing
Shell-sed命令的使用
. net cross platform principle (Part I)
STM32__03—初识定时器
Expression "func" tSource, object "to expression" func "tSource, object" []
[problem solving] [show2012] random tree
Further study of data visualization
MySQL master-slave configuration under CentOS
[registration] tf54: engineer growth map and excellent R & D organization building
EF core in ASP Generate core priority database based on net entity model
New keyword learning and summary
Shell脚本——Shell编程规范及变量
SPC introduction
Multithreaded @ async thread pool
[PROJECT] small hat takeout (8)
[C#] 彻底搞明白深拷贝
1-2 characteristics of nodejs