当前位置:网站首页>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
边栏推荐
- Getting started with JDBC
- Kingdee Cloud Star API calling practice
- Interface document yaml
- C# Task. Delay and thread The difference between sleep
- 蓝桥杯省一之路06——第十二届省赛真题第二场
- First knowledge of go language
- 【WPF绑定3】 ListView基础绑定和数据模板绑定
- 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
- org. apache. parquet. schema. InvalidSchemaException: A group type can not be empty. Parquet does not su
猜你喜欢
VLAN advanced technology, VLAN aggregation, super VLAN, sub VLAN
Smart doc + Torna generate interface document
Dancenn: overview of byte self-developed 100 billion scale file metadata storage system
Detailed explanation of Niuke - Gloves
Nodejs installation and environment configuration
Mock test using postman
TypeError: set_ figure_ params() got an unexpected keyword argument ‘figsize‘
自定义my_strcpy与库strcpy【模拟实现字符串相关函数】
Go language, array, string, slice
JS, entries(), keys(), values(), some(), object Assign() traversal array usage
随机推荐
Read a blog, re understand closures and tidy up
Smart doc + Torna generate interface document
文件操作《二》(5000字总结篇)
Generation of barcode and QR code
Talk about browser cache control
Aiot industrial technology panoramic structure - Digital Architecture Design (8)
Paging SQL
. net cross platform principle (Part I)
Bytevcharts visual chart library, I have everything you want
Milvus 2.0 質量保障系統詳解
Zhimeng dedecms security setup Guide
计算饼状图百分比
Wiper component encapsulation
freeCodeCamp----shape_ Calculator exercise
Derivation of Σ GL perspective projection matrix
Shell-cut命令的使用
Promise (II)
MySQL restores data through binlog file
Nifi fast installation and file synchronization
Calculation formula related to tolerance analysis