当前位置:网站首页>sed命令
sed命令
2022-06-12 03:20:00 【望月湖】
sed参考文档
语法:
sed [-hnV][-e<script>][-f<script文件>][文本文件]
-e<script>或--expression=<script>以选项中指定的script来处理输入的文本文件。如果不加-e ,那么sed后面的命令要用'命令....'单引号包括起来- -f<script文件>或–file=<script文件> 以选项中指定的script文件来处理输入的文本文件。
- -h或–help 显示帮助。
- -n或–quiet或–silent 仅显示script处理后的结果。
- -V或–version 显示版本信息。
动作说明:
- a :新增, a 的后面可以接字串,而这些字串会出现在新的一行(当前行的下一行)
- c :取代, c 的后面可以接字串,这些字串可以取代 n1,n2 之间的行
- d :删除,因为是删除,所以 d 后面通常不接任何参数;
- i :插入, i 的后面可以接字串,而这些字串会在新的一行出现(目前的上一行);
- p :打印,将某个选择的数据印出。通常 p 会与参数 sed -n 一起运行
- s :取代,通常这个 s 的动作可以搭配正规表示法
命令案例
-e 注意,这里所有的增删改命令都只是修改输出内容,而不修改原本文件内容
#这里的$代表最后一行。 #添加 a sed -e 4a\newLine testfile # 在文件第4行添加"newLine"内容 nl testfile | sed '2a drink tea' #在第二行后(即加在第三行) 加上drink tea nl testfile | sed '2i drink tea' #在第二行前插入drink tea # 添加多行用 \ 分隔 nl testfile | sed '2a drink tea \ 第二行内容' #在第二行后(即加在第三行) 加上drink tea 以及第二行内容, #删除 d nl testfile | sed '2,5d' # 删除testfile文件的2~5行内容 nl testfile | sed '3,$d' # 要删除第 3 到最后一行,$代表最后一行 nl testfile | sed '/oo/d' # 删除带有oo的行 # 替换 c nl testfile | sed '2,5c replace 2-5 number' # 将2~5行替换成 replace 2-5 number # 正则搜索替换 s,搜索字符串的 sed 's/要被取代的字串/新的字串/g' #全局替换字符串,g代表全局, sed 's/要被取代的字串/新的字串/' #只替换第一处搜索到的内容-n 列出
nl testfile | sed -n '5,7p' #输出5~7行 nl testfile | sed -n '/oo/p' #搜索出带有oo的行 nl testfile | sed -n '/oo/{s/oo/kk/;p;q}' #搜索带oo的行,并执行{}里面的命令,-i 修改
sed -i 's/oo/kk/g' testfile # 修改testfile,全局替换oo为kk sed -i 's/oo/kk/g' ./test* # 修改test开头的文件,多个命令编辑
#一条 sed 命令,删除 testfile 第三行到末尾的数据,并把 HELLO 替换为 RUNOOB nl testfile | sed -e '3,$d' -e 's/HELLO/RUNOOB/'
边栏推荐
- Final summary of addition, deletion, modification and query - 2.1 (single table - addition, deletion, modification and query)
- 【点云压缩】Sparse Tensor-based Point Cloud Attribute Compression
- Comparison of scores
- [Hongmeng] use the timer to play a simple game of robbing red envelopes
- Sequence list and linked list - primary level
- 1187_ C language implementation of hysteresis processing
- The market value has exceeded $3trillion. Why should apple, which has been criticized as a loser, rise again and again?
- Laravel 8 selects JWT for interface verification
- About 100 to realize the query table? Really? Let's experience the charm of amiya.
- Recommend 6 office software, easy to use and free, double the efficiency
猜你喜欢

Redis gets the set of keys prefixed with XXX

Demand and business model innovation - demand 10- observation and document review

Exemple de projet d'applet Wechat - calculatrice de constitution

The road of global evolution of vivo global mall -- multilingual solution
![[Business Research Report] Research Report on super automation technology and application (2022) -- download link attached](/img/c9/6d34bed3bde0044270c5dca269d6b9.jpg)
[Business Research Report] Research Report on super automation technology and application (2022) -- download link attached

1187_ C language implementation of hysteresis processing

In 2022, don't you know the difference between arrow function and ordinary function?

The rise of another domestic mobile phone chip is close to the height reached by Huawei

One article to show you how to understand the harmonyos application on the shelves

分數大小的比較
随机推荐
mysql/oracle 以唯一时间为分界,小于等于该时间求和,大于该时间求和
2020-12-07
微信小程序项目实例——体质计算器
[Business Research Report] 2021 global mobile game player white paper - download link attached
Leetcode 6[finding rules] Z-transform the leetcode path of heroding
ARD3M电动机保护器在煤炭行业中的应用
Penetration test - file upload
简单的数据库连接示例
laravel 8 选用 jwt 进行接口验证
ics-07
oralce 处理列转行的三种方式 最后生成表格样式数据
Interpreting Julia's 2021: step by step towards the mainstream programming language
JSON and XML pros and cons
Go syntax variable
cupp字典生成工具(同类工具还有crunch)
Introduce the functions of the new project aleo
【点云压缩】Variational Image Compression with A Scale Hyperprior
Wechat applet project example - Fitness calculator
AI interview bag | Netease mutual entertainment AI Lab artificial intelligence research engineers share on both sides
Restful interface design specification [for reference only]