当前位置:网站首页>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 .
边栏推荐
- Dark horse notes - Common APIs
- 【Spark】. Explanation of several icons of scala file in idea
- B - Bridging signals
- Arcpy - - utilisation de la fonction insertlayer (): ajout de calques dans un document de carte
- MariaDB study notes
- A primary multithreaded server model
- Processsing function random
- Design of four kinds of linear phase FIR filters -- complete set of Matlab source code
- Common creation and usage of singletons
- [how to connect the network] Chapter 1: the browser generates messages
猜你喜欢

Processing function translate (mousex, mousey) learning

ES基于Snapshot(快照)的数据备份和还原
![[how to connect the network] Chapter 1: the browser generates messages](/img/6b/e85f29ba97c261e01e177b5e77c423.png)
[how to connect the network] Chapter 1: the browser generates messages

5月产品升级观察站

MariaDB study notes
![[how to connect the network] Chapter 2 (next): receiving a network packet](/img/f5/33e1fd8636fcc80430b3860d069866.png)
[how to connect the network] Chapter 2 (next): receiving a network packet

Decorator

Prototype

Explain C language 10 in detail (C language series)

Basic configuration and test of Beifu twincat3 NCI in NC axis interface
随机推荐
Learning Processing Zoog
Arcpy -- use of insertlayer() function: adding layers to map documents
Beifu twincat3 can read and write CSV and txt files
Mode pont
ES中索引别名(alias)的到底有什么用
Decorator
Update and download of Beifu EtherCAT XML description file
Digital signal processing -- Design of linear phase type (Ⅰ, Ⅲ) FIR filter (1)
QT . Establishment and use of pri
7-1 n queen problem
LAMP编译安装
E - Apple Catching
Oplg: new generation cloud native observable best practices
Explain C language 11 in detail (C language series)
KITTI Tracking dataset whose format is letf_ top_ right_ bottom to JDE normalied xc_ yc_ w_ h
Beifu realizes the control of time slice size and quantity through CTU and ton
Thinking caused by the error < note: candidate expectations 1 argument, 0 provided >
MySQL explanation (I)
What features are added to Photoshop 2022 23.4.1? Do you know anything
H - Sumsets POJ 2229