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;
#}
相关推荐
奔跑吧邓邓子9 小时前
正则表达式:开启文本处理的魔法之门
正则表达式·文本处理·高效应用
相知-.1 天前
shell正则表达式
linux·运维·正则表达式
面朝大海,春不暖,花不开3 天前
使用 Python 正则表达式实现文本替换与电话号码规范化
python·mysql·正则表达式
前端小白从0开始3 天前
关于前端常用的部分公共方法(二)
前端·vue.js·正则表达式·typescript·html5·公共方法
岁忧3 天前
LeetCode 高频 SQL 50 题(基础版)之 【高级字符串函数 / 正则表达式 / 子句】· 下
sql·leetcode·正则表达式
岁忧3 天前
MySQL中【正则表达式】用法
数据库·mysql·正则表达式
htj105 天前
C# 使用正则表达式
正则表达式·c#
ZZZKKKRTSAE5 天前
快速上手Linux全局搜索正则表达式(grep)
linux·服务器·正则表达式
Kusunoki_D6 天前
Python-正则表达式(re 模块)
python·正则表达式
数字芯片实验室6 天前
正则表达式的前世今生
正则表达式