当前位置:网站首页>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
边栏推荐
- Smart doc + Torna generate interface document
- Path environment variable
- [registration] tf54: engineer growth map and excellent R & D organization building
- Milvus 2.0 détails du système d'assurance de la qualité
- Bottom processing of stack memory in browser
- How to implement distributed locks with redis?
- How much do you know about the process of the interview
- Promise (II)
- Shell-入门、变量、以及基本的语法
- MySQL master-slave configuration under CentOS
猜你喜欢
Milvus 2.0 质量保障系统详解
Document operation II (5000 word summary)
PyMySQL
Shell script -- shell programming specification and variables
Scope and scope chain in JS
Net standard
How vscode compares the similarities and differences between two files
. net cross platform principle (Part I)
Detailed explanation of Milvus 2.0 quality assurance system
SQL database
随机推荐
Variable length parameter__ VA_ ARGS__ Macro definitions for and logging
Promise (III)
Lock锁
Do you really understand the principle of code scanning login?
Further study of data visualization
Shortcut keys (multiline)
PHP高效读大文件处理数据
C# Task. Delay and thread The difference between sleep
MySQL restores data through binlog file
PostgreSQL column storage and row storage
Zhongang Mining: Fluorite Flotation Process
Milvus 2.0 质量保障系统详解
Node access to Alipay open platform sandbox to achieve payment function
Bottom processing of stack memory in browser
Nacos + aspnetcore + Ocelot actual combat code
Kingdee Cloud Star API calling practice
Input file upload
PHP efficiently reads large files and processes data
freeCodeCamp----shape_ Calculator exercise
信息摘要、数字签名、数字证书、对称加密与非对称加密详解