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;
#}
相关推荐
坐吃山猪14 小时前
Python09_正则表达式
开发语言·python·正则表达式
橙露20 小时前
Python 正则表达式:文本清洗与信息提取速通手册
python·正则表达式·easyui
XiaoQiao6669993 天前
pytnon中正则表达式小题详解
python·正则表达式
gCode Teacher 格码致知3 天前
Python基础教学:正则表达式中的忽略大小写以及符号“-“的问题-由Deepseek产生
python·正则表达式
ths5124 天前
Python 正则表达式实战指南:从入门到精通(12 个高频案例)(三)
python·正则表达式
ths5124 天前
Python 正则表达式学习笔记(小白超详细版)(一)
python·正则表达式
kcuwu.7 天前
Python 正则表达式从入门到实战
数据库·python·正则表达式
羊小蜜.7 天前
Mysql 07: 正则表达式查询(REGEXP)全解
数据库·mysql·正则表达式
Dxy12393102167 天前
正则表达式如何匹配提取文章日期
数据库·mysql·正则表达式
Dxy123931021610 天前
Python正则表达式判断姓名:详细解析
python·mysql·正则表达式