当前位置:网站首页>Shell-sed命令的使用
Shell-sed命令的使用
2022-04-23 17:04:00 【魔笛Love】
sed
sed是一种流编辑器,它一次处理一行内容。处理时,把当前处理的行存储在临时缓冲区中,称为“模式空间”,接着用sed命令处理缓冲区中的内容,处理完成后,把缓冲区的内容送往屏幕。接着处理下一行,这样不断重复,直到文件末尾。文件内容并没有改变,除非你使用重定向存储输出。
基本用法
sed [选项参数] 'command' filename
选项参数说明
| 选项参数 | 功能 |
|---|---|
| -e | 直接在指令列模式上进行sed的动作编辑。 |
常用命令功能描述
| 命令 | 功能描述 |
|---|---|
| a | 新增,a的后面可以接字串,在下一行出现 |
| d | 删除 |
| s | 查找并替换 |
案例实操
# 数据准备
[bd@localServer ~]$ touch sed.txt
[bd@localServer ~]$ vim sed.txt
fu xia
zhou men
wo wo
lai lai
le le
### 将“wo shi”这个单词插入到sed.txt第二行下,打印。
[bd@localServer ~]$ sed '2a wo shi' sed.txt
fu xia
zhou men
wo shi
wo wo
lai lai
le le
#### 源文件没有改变
[bd@localServer ~]$ cat sed.txt
fu xia
zhou men
wo wo
lai lai
le le
### 删除sed.txt文件所有包含wo的行
[bd@localServer ~]$ sed '/wo/d' sed.txt
fu xia
zhou men
lai lai
le le
### 将sed.txt文件中wo替换为ni,g表示global为全局操作,不加的话只处理第一个
[bd@localServer ~]$ sed 's/wo/ni/g' sed.txt
fu xia
zhou men
ni ni
lai lai
le le
### 将sed.txt文件中的第二行删除并将wo替换为ni
[bd@localServer ~]$ sed -e '2d' -e 's/wo/ni/g' sed.txt
fu xia
ni ni
lai lai
le le
版权声明
本文为[魔笛Love]所创,转载请带上原文链接,感谢
https://blog.csdn.net/clearlxj/article/details/121742569
边栏推荐
- [problem solving] [show2012] random tree
- [PROJECT] small hat takeout (8)
- Smart doc + Torna generate interface document
- Kingdee Cloud Star API calling practice
- An essay on the classical "tear down the wall in thinking"
- El date picker limits the selection range from the current time to two months ago
- vscode如何比较两个文件的异同
- org. apache. parquet. schema. InvalidSchemaException: A group type can not be empty. Parquet does not su
- Summary of common websites
- JSON deserialize anonymous array / object
猜你喜欢

STM32__03—初识定时器

Detailed explanation of Milvus 2.0 quality assurance system

ACL 2022 | dialogved: a pre trained implicit variable encoding decoding model for dialogue reply generation

Bottom processing of stack memory in browser

feign报400处理

Smart doc + Torna generate interface document

Milvus 2.0 détails du système d'assurance de la qualité

On lambda powertools typescript

Milvus 2.0 質量保障系統詳解

STM32__ 03 - beginner timer
随机推荐
Quick install mongodb
Path environment variable
Further study of data visualization
PHP efficiently reads large files and processes data
TypeError: set_figure_params() got an unexpected keyword argument ‘figsize‘
freeCodeCamp----shape_ Calculator exercise
RTKLIB 2.4.3源码笔记
【解决报错】Error in v-on handler: “TypeError: Cannot read property ‘resetFields’ of undefined”
Baidu Map Case - modify map style
Collect blog posts
Mock test using postman
groutine
Promise (I)
Scope and scope chain in JS
Generation of barcode and QR code
How to implement distributed locks with redis?
MySQL master-slave replication
1-1 NodeJS
ACL 2022 | DialogVED:用于对话回复生成的预训练隐变量编码-解码模型
面试百分百问到的进程,你究竟了解多少