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;
#}
相关推荐
TOWNST14 小时前
正则表达式使用知识(日常翻阅)
java·python·正则表达式
XU磊26014 小时前
深入 Java 正则表达式源码:透视 Matcher.group(int) 的分组提取机制
正则表达式
斯内科2 天前
Python进阶(1):正则表达式
python·正则表达式
程序员总部2 天前
Python中如何用正则表达式精准匹配IP地址?
python·tcp/ip·正则表达式
王小二_Leon3 天前
JAVA中正则表达式的入门与使用
java·正则表达式
搜搜秀3 天前
find指令中使用正则表达式
linux·运维·服务器·正则表达式·bash
Jwoka4 天前
正则表达式学习笔记
笔记·python·正则表达式·re
晨曦5432104 天前
python——正则表达式
开发语言·正则表达式
学c真好玩5 天前
4.7正则表达式
正则表达式
专注VB编程开发20年6 天前
C#,VB.NET正则表达式法替换代码
正则表达式·c#·.net·vb.net