当前位置:网站首页>正则 和 sed 练习
正则 和 sed 练习
2022-07-27 06:50:00 【空丶白灬】
一、正则
1、显示/etc/rc.d/rc.sysinit文件中以不区分大小的h开头的行;
grep -i "^h" /etc/rc.d/rc.sysinit
2、显示/etc/passwd中以sh结尾的行;
grep sh$ /etc/passwd
3、显示/etc/fstab中以#开头,且后面跟一个或多个空白字符,而后又跟了任意非空白字符的行;
grep -E "^# +[^[:space:]]+" /etc/fstab
4、查找/etc/rc.d/rc.local中包含“以to开始并以to结尾”的字串行;
grep "^to.*to$" /etc/rc.d/rc.local
5、查找/etc/inittab中含有“以s开头,并以d结尾的单词”模式的行;
grep -w "\<s[a-Z]*d\>" /etc/inittab
6、查找ifconfig命令结果中的1-255之间的整数;
ifconfig | grep -oE "\<[1-9]|1[0-9][0-9]|2[0-4][1-9]|25[0-5]\>"
7、显示/var/log/secure文件中包含“Failed”或“FAILED”的行;
grep -E "(Faild|FAILED)" /var/log/secure
8、在/etc/passwd中取出默认shell为bash的行;
grep bash$ /etc/passwd
9、以长格式列出/etc/目录下以ns开头、.conf结尾的文件信息;
ll /etc | awk '{print $NF }'|grep -E "^(ns).*\.(conf)$"
10、高亮显示passwd文件中冒号,及其两侧的字符;
grep -E "(.:+.)" /etc/passwd
二、sed
1、删除/etc/grub2.conf文件中所有以空白开头的行行首的空白字符
sed 's/^ \+//' /etc/grub2.cfg
2、删除/etc/fstab文件中所有以#开头,后面至少跟一个空白字符的行的行首的#和空白字符
sed -r 's/^# \+//' /etc/fstab
3、在/root/install.log每一行行首增加#号
sed 's/^.*/#&/' /etc/fstab
4、在/etc/fstab文件中不以#开头的行的行首增加#号
sed 's/^[^#]/#&/' /etc/fstab
5、利用sed 取出ifconfig命令中本机的IPv4地址
ifconfig | sed -n 2p | sed 's/ *inet//' | sed 's/ net.*//'
6、关闭本机SELinux的功能
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux
7、在/etc/hosts配置文件中添加内容
sed -i '1 i 192.168.198.1' /etc/hosts
边栏推荐
- The error of QT connecting SQLite database and its modification
- 单片机多级菜单
- 单臂路由(讲解+实验)
- ChromeDriver下载-自用
- 杂谈:跟女儿聊为啥要学好文化课
- glGetUniformLocation,glUniform4f
- DRConv-pytorch改称输出和输入一样的尺寸
- Use Amazon dynamodb and Amazon S3 combined with gzip compression to maximize the storage of player data
- functools模块
- sql语句批量更新 时间减去1天
猜你喜欢

Prior Attention Enhanced Convolutional Neural Network Based Automatic Segmentation of Organs at Risk

C language implementation of guessing numbers Games project practice (based on srand function, rand function, switch statement, while loop, if condition criterion, etc.)

C common function integration-3

Use reflection to dynamically modify annotation attributes of @excel

正则表达式基础整理

Bash: create a function that returns a Boolean value

Single arm routing (explanation + experiment)

STM32_ Find the cause of entering hardfault_ Handler's function

Prior Attention Enhanced Convolutional Neural Network Based Automatic Segmentation of Organs at Risk

在mac中使用docker来搭建oracle数据库服务器
随机推荐
(2022 Hangdian multi school III) 1011.taxi (Manhattan maximum + 2 points)
Turn off the auto start function of Oracle service in centos7
Zabbix: map collected values to readable statements
Help send a recruitment, base all over the country. If you are interested, you can come and have a look
Examples of Oracle triggers
Okaleido tiger is about to log in to binance NFT in the second round, which has aroused heated discussion in the community
Flynk de duplication (2) solve the hot issues in the process of flynk and flynk SQL de duplication
简单的轮播图
Summary of several common ways to join dimension tables in Flink
flink原理(一) 状态的TTL管理、容错机制
Clickhouse notes 1 | introduction, features | installation and use based on centos7 system | common data types | mergetree table engine | SQL operation
User unlock sm04 sm12
Port forwarding summary
Tcp/ip protocol analysis (tcp/ip three handshakes & four waves + OSI & TCP / IP model)
(2022 Niuke multi school III) j-journey (Dijkstra)
UI gesture actions of uiautomator common classes
Top ten interview questions for software testing (with answers and analysis)
Shell condition test, judgment statement and operator of shell system learning
Essay: college entrance examination
Demonstrate the use of foreign keys with Oracle