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;
#}
相关推荐
木人舟11 小时前
正则表达式快速入门
正则表达式
BeanInJ1 天前
JAVA字符串与正则表达式
java·正则表达式
林深的林1 天前
正则表达式(2)匹配规则
正则表达式
叶域2 天前
正则表达式(复习)
大数据·python·正则表达式
运维小贺4 天前
Nginx常用的模块
运维·nginx·正则表达式
Viooocc5 天前
正则表达式
正则表达式
vvilkim5 天前
开发中常用的正则表达式规则与应用
正则表达式
林深的林6 天前
正则表达式(1)
正则表达式
ThisIsClark7 天前
【玩转正则表达式】正则表达式常用语法汇总
正则表达式
ThisIsClark7 天前
【玩转正则表达式】替换与正则表达式的结合
正则表达式