Linux基础知识:Sed单行处理与多行处理格式

本文介绍了Linux中的Sed命令,包括元字符的概念,Sed的单行处理和多行处理模式,以及如何使用Sed进行文本替换和操作。对于Linux运维人员和系统管理员来说,掌握Sed的用法对于日常文本处理任务非常实用。
摘要由CSDN通过智能技术生成

 1、元字符介绍

.  匹配除换行符外的任意单个字符
*  匹配任意一个跟在它前面的字符
[] 匹配方括号中的字符类中的任意一个
^  匹配开头
$  匹配结尾
\  转义后面的特殊字符

+ 匹配前面的正则表达式至少出现一次
?匹配前面的正则表达式出现零次或一次
|  匹配它前面或后面的正则表达式


-----------------------

举例说明.和$,借助文本查找工具grep

[root@harbor ~]# grep password /root/anaconda-ks.cfg
# Root password

[root@harbor ~]# grep pass... /root/anaconda-ks.cfg
auth --enableshadow --passalgo=sha512
# Root password
You have new mail in /var/spool/mail/root

[root@harbor ~]# grep pass....$ /root/anaconda-ks.cfg
# Root password

[root@harbor ~]# grep  pass* /root/anaconda-ks.cfg
auth --enableshadow --passalgo=sha512
# Root password[root@harbor ~]# 

[root@harbor ~]# grep  ^#  /root/anaconda-ks.cfg
#version=DEVEL
# System authorization information
# Use CDROM installation media
# Use graphical install
# Run the Setup Agent on first boot
# Keyboard layouts
# System language
# Network information
# Root password
# System services
# System timezon
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值