sed 一点点记忆

sed用法实例1(我用的最多,超级无敌的用法)

格式:/ # b 可以换成你想要的字符

复制代码
sed -i '//s///' 文本文件
sed -i '##s###' 文本文件
sed -i 'bbsbbb' 文本文件

描述

通过正则表达式过滤你想要的行,替换该行的内容

1、s前面用于过滤,不需要替换所以只有两个分割符(//)

2、s后面用于替换,需要替换所以有三个分割符(///)

3、s前面:两个分割符之间写正则表达式过滤你想要的行

4、s后面:三个分割符,第一个和第二个之间写你想替换的内容,第二个和第三个之间写你想替换成什么

5、正则表达式书写超级简单,记住就行-但是要一点点去记忆,只有常用的东西面试的时候才会脱口而出

用法

复制代码
cat test-nginx.conf
文本内容如下:
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#location ~ \.php$ {
#    root           html;
#    fastcgi_pass   127.0.0.1:9000;
#    fastcgi_index  index.php;
#    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
#    include        fastcgi_params;
#}

sed -i '/\/scripts$/s/\/scripts/$document/' 文本文件
替换后内容:
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#location ~ \.php$ {
#    root           html;
#    fastcgi_pass   127.0.0.1:9000;
#    fastcgi_index  index.php;
#    fastcgi_param  SCRIPT_FILENAME  $document$fastcgi_script_name;
#    include        fastcgi_params;
#}
相关推荐
XMYX-012 小时前
33 - Go 文本模板 template:从入门到原理深挖
golang·正则表达式
XMYX-016 小时前
32 - Go 正则表达式:从匹配字符串到理解 RE2 引擎
golang·正则表达式
程序员榴莲1 天前
Python 正则表达式入门:从匹配手机号到提取文本内容
python·正则表达式
红茶要加冰3 天前
七、正则表达式
linux·运维·正则表达式·shell
Pocker_Spades_A3 天前
Python快速入门专业版(五十八)——正则表达式(re):爬虫文本提取利器(从语法到实战)
爬虫·python·正则表达式
红茶要加冰4 天前
九、文本处理三剑客——sed
linux·运维·服务器·正则表达式·shell
Bug-制造者4 天前
正则表达式 vs Shell通配符:彻底分清,告别命令行踩坑
linux·正则表达式
剑神一笑5 天前
Linux top 命令深度解析:进程监控的性能优化实战
linux·运维·正则表达式
jayson.h6 天前
正则表达式:从文件名提取器件编号
开发语言·python·正则表达式
水木流年追梦6 天前
大模型入门-应用篇3-Agent智能体
开发语言·python·算法·leetcode·正则表达式