当前位置:网站首页>Sed command
Sed command
2022-06-12 03:24:00 【Wangyue Lake】
sed Reference documents
grammar :
sed [-hnV][-e<script>][-f<script file >][ text file ]
-e<script>or--expression=<script>As specified in the options script To process the input text file . If not -e , that sed For the following commands' command ....'Single quotation marks are enclosed- -f<script file > or –file=<script file > As specified in the options script File to process the input text file .
- -h or –help Display help .
- -n or –quiet or –silent Show only script The result of the treatment .
- -V or –version Display version information .
Action description :
- a : newly added , a You can use a string after , These strings will appear on a new line ( The next line of the current line )
- c : replace , c You can use a string after , These strings can replace n1,n2 Between the lines
- d : Delete , Because it's deletion , therefore d It is usually not followed by any parameters ;
- i : Insert , i You can use a string after , And these strings will appear on a new line ( The current line );
- p : Print , Print a selected data out . Usually p And parameters sed -n Run together
- s : replace , Usually the s The action can be combined with normal expression
Command cases
-e Be careful , All the add, delete and modify commands here are just to modify the output content , Without modifying the contents of the original document
# there $ For the last line . # add to a sed -e 4a\newLine testfile # In Document No 4 Line add "newLine" Content nl testfile | sed '2a drink tea' # After the second line ( Add to the third line ) add drink tea nl testfile | sed '2i drink tea' # Insert... Before the second line drink tea # Add multi line \ Separate nl testfile | sed '2a drink tea \ The second line ' # After the second line ( Add to the third line ) add drink tea And the second line , # Delete d nl testfile | sed '2,5d' # Delete testfile Of documents 2~5 Row content nl testfile | sed '3,$d' # To delete the 3 To the last row ,$ For the last line nl testfile | sed '/oo/d' # Delete with oo The line of # Replace c nl testfile | sed '2,5c replace 2-5 number' # take 2~5 Replace the line with replace 2-5 number # Regular search replacement s, Of search string sed 's/ String to be replaced / New string /g' # Global replacement string ,g On behalf of the whole , sed 's/ String to be replaced / New string /' # Replace only the first search-n List
nl testfile | sed -n '5,7p' # Output 5~7 That's ok nl testfile | sed -n '/oo/p' # We found out that oo The line of nl testfile | sed -n '/oo/{s/oo/kk/;p;q}' # Search band oo The line of , And implement {} The order inside ,-i modify
sed -i 's/oo/kk/g' testfile # modify testfile, Global replacement oo by kk sed -i 's/oo/kk/g' ./test* # modify test Opening file ,Multiple command editing
# One sed command , Delete testfile Data from the third line to the end , And put HELLO Replace with RUNOOB nl testfile | sed -e '3,$d' -e 's/HELLO/RUNOOB/'
边栏推荐
- 2020-12-12
- Special information | liquor (Baijiu, beer, wine)
- Go recursive infinite classification
- central limit theorem
- cupp字典生成工具(同类工具还有crunch)
- 微信小程序项目实例——我有一支画笔(画画)
- postgresql基本介绍以及部署使用
- Domestic mobile phones are snubbing low-end consumers, and Nokia provides them with high-quality products
- vim命令大全
- Requirements and business model innovation - Requirements 12 - process oriented modeling
猜你喜欢

微服务概念及介绍

余压监控系统在高层民用建筑的应用

Application of acrelcloud-6000 secure power cloud platform in a commercial plaza

Detailed explanation of data platform SQL development and function use

I2C协议概述

AcrelCloud-6000安全用电云平台在某商业广场的应用

如何防止商场电气火灾的发生?
![[Hongmeng] use the timer to play a simple game of robbing red envelopes](/img/27/32b65dc90db7f6ece24ad39ff9b0ef.png)
[Hongmeng] use the timer to play a simple game of robbing red envelopes

Wechat applet project example - renju for two

安科瑞抗晃电产品在河北某化工项目的应用
随机推荐
Final summary of addition, deletion, modification and query - 2.1 (single table - addition, deletion, modification and query)
Notes relatives à l'application du certificat de l'AC et de la paire de clés
Wechat applet project example - I have a paintbrush (painting)
简单的数据库连接示例
The idea of setting the flash memory management and resource size, and the quantitative relationship among parallelism, slot, and taskmanager quantity
Inverted string - two solutions
2020-12-17
Laravel 8 selects JWT for interface verification
MySQL partition table create delete modify view
I2C protocol overview
What is a request response pair called? [repeat] - what is a request response pair called? [duplicate]
[Business Research Report] forward looking report on urban renewal and development in China in 2021 - download link attached
1187_ C language implementation of hysteresis processing
【点云压缩】Sparse Tensor-based Point Cloud Attribute Compression
CA證書及密鑰對應用筆記
Sparse tensor based point cloud attribute compression
Demand and business model innovation - demand 11 - overview of demand analysis
[Bank Research Report] technology enabled retail finance carbon neutral development report (2022) - download link attached
[DFS "want" or "don't"] seek subsets; Seeking combination
TCP three handshakes and four waves