当前位置:网站首页>Sed editor
Sed editor
2022-06-26 13:22:00 【C chord~】
Catalog
5、 ... and . Delete 、 Replace 、 Insert
introduction :
At work sed Editors are used a lot , Therefore, for operation and maintenance, it is necessary to master sed The use of editors is also important .
One .sed Editor
- sed Is a flow editor , The stream editor will edit the data stream based on a set of rules provided in advance before the editor processes the data .
- sed The editor can process the data in the data stream according to the command , These commands are either entered from the command line , Or stored in a command text file .
Two 、sed Editor workflow
2.1 Read
- sed From the input stream ( file 、 The Conduit 、 The standard input ) Read a line in and store it in a temporary buffer ( Also called pattern space ,pattern space)
2.2 perform
- By default , be-all sed Commands are executed sequentially in pattern space , Unless the address of the line is specified , otherwise sed The command will be executed on all lines in turn .
2.3 Show
- Send the modified content to the output stream . After sending the data , Mode space will be cleared . Before all the contents of the file are processed , The above process will be repeated , Until all content is processed .
2.4 Add
- Before all the contents of the file are processed , The above process will be repeated , Until all content is processed .
- By default, all sed Commands are executed in pattern space , So the input file doesn't change , Unless you're using redirection to store output
3、 ... and . Command format
- sed [ Options ] ' operation ' Parameters
- sed [ Options ] -f scriptfile Parameters
Common options :
- -e or - -expression= # Indicates that the input text file is processed with the specified command , Only one operation command can be omitted , One It is generally used when executing multiple operation commands
- f or - -file= # Indicates that the input text file is processed with the specified script file
- h or - -help # Display help
- -n、- -quiet or silent # prohibit sed Editor output , But you can p Command to complete the output
- -i # Modify the target text file directly
Common operations
operation explain
s Replace , Replace specified characters
d Delete , Delete selected rows
a increase , Add a line below the current line to specify
i Insert , In the selected line , Insert a specified line above
c Replace , Replace the selected row with the specified content
y Character conversion , The character length before and after conversion must be the same
p Print , If you also specify a row , Indicates to print the specified line ; If no line is specified , It means printing everything ; If there are non printing characters , with
ASCII Code output . It is usually associated with “-n” Use options together
= Print line number
l ( A lowercase letter L) Print text in the data stream and unprintable ASCII character ( Like the terminator $、 tabs \t)
Four . Use the address
sed The editor has 2 Address mode :1. Represent row intervals in numerical form
2. Use text mode to filter travel
5、 ... and . Delete 、 Replace 、 Insert
Delete
- sed 'd' 1.txt # Delete all
- sed '$d' 1.txt # Delete last line
- sed '2,5d' 1.txt # Delete 2-5 That's ok
Replace
Format : Line scope s/ Old characters / New character / Replace mark
4 Two alternative markers :1. Numbers : Indicates where the new string will replace the match
2.g: Indicates that the new character will replace all matches
3.p: Print the line that matches the replace command , And -n Use it together
4.w file : Write the result of the replacement to a file
Insert
- sed '1a 520' 1.txt # stay 1.txt Insert... After the first line of the file 520
- sed '1i 520' 1.txt # stay 1.txt Insert before the first line of the file 520
- sed '/r/etc/resolv.conf' 1.txt # stay 1.txt Insert text after the first line in the file
summary :
sed The use of is very common 、 It's also important. , Therefore, as an operation and maintenance engineer, you must master sed The usage and theory of .
边栏推荐
- A collection of common tools for making we media videos
- 8、【STM32】定时器(TIM)——中断、PWM、输入捕获实验(一文精通定时器)
- Beifu PLC realizes data power-off maintenance based on cx5130
- Common faults of MySQL database - forgetting database password
- What features are added to Photoshop 2022 23.4.1? Do you know anything
- 5月产品升级观察站
- First pass! Baidu AI Cloud Xiling platform has obtained the authoritative certification of digital human ability evaluation from the Institute of information technology
- Processsing mouse interactive learning
- Uva10341 solve it
- 5+api, clear application cache
猜你喜欢

IDC report: the AI cloud market share of Baidu AI Cloud ranks first for six consecutive times

mysql讲解(一)

Use the script to crawl the beautiful sentences of the sentence fan website and store them locally (blessed are those who like to excerpt!)

12 SQL optimization schemes summarized by old drivers (very practical)

ES基于Snapshot(快照)的数据备份和还原

橋接模式(Bridge)

享元模式(Flyweight)

IDC报告:百度智能云AI Cloud市场份额连续六次第一

装饰器(Decorator)

Chapter 10 setting up structured logging (2)
随机推荐
awk工具
Some conclusions about Nan
Use the script to crawl the beautiful sentences of the sentence fan website and store them locally (blessed are those who like to excerpt!)
Bifu divides EtherCAT module into multiple synchronization units for operation -- use of sync units
计算两点之间的距离(二维、三维)
Mysql database explanation (III)
HDU 3709 Balanced Number
Prototype
Word document export (using fixed template)
Analysis of state transition diagram of Beifu NC axis
H5视频自动播放和循环播放
Mysql database explanation (IV)
Explain C language 10 in detail (C language series)
KITTI Detection dataset whose format is letf_ top_ right_ bottom to JDE normalied xc_ yc_ w_ h
There are many contents in the widget, so it is a good scheme to support scrolling
To solve the difficulties of small and medium-sized enterprises, Baidu AI Cloud makes an example
H - Sumsets POJ 2229
D - skiing
G - Cow Bowling
C language: Exercise 2