当前位置:网站首页>SED 学以致用
SED 学以致用
2022-04-23 14:10:00 【小灰墩墩】
1、删除centos7系统/etc/grub2.cfg文件中所有以空白开头的行行首的空白字符。
# sed -nr 's/^[[:blank:]]+//p' /etc/grub2.cfg
2、删除/etc/fstab文件中所有以#开头,后面至少跟一个空白字符的行的行首的# 和空白字符。
# sed -nr 's/^#[[:blank:]]+(.*)/\1/p' /etc/fstab
3、在centos6系统/root/install.log每一行行首增加#号。
# sed -nr 's/(.*)/#\1/p' /root/install.log
4、在/etc/fstab文件中不以#开头的行的行首增加#号。
# sed -nr '/^#/!p' /etc/fstab |sed -nr 's/.*/#&/p'
# sed -nr 's/^[^#]/#/p' /etc/fstab
5、处理/etc/fstab路径,使用sed命令取出其目录名和基名。
# echo /etc/fstab |sed -nr 's@(^\/.*\/)(.*)@\2@p'
fstab
# echo /etc/fstab |sed -nr 's@(^\/.*\/)(.*)@\1@p'
/etc/
6、利用sed 取出ifconfig命令中本机的IPv4地址。
# ifconfig eth0 |sed -nr 's/.*inet (.*) netmask.*/\1/p'
7、统计centos安装光盘中Package目录下的所有rpm文件的以.分隔倒数第二个字段的重复次数
# ls *.rpm|sed -r 's@^.*\.([^.]+)\.rpm$@\1@'|sort|uniq -c
# ls *.rpm |sed -nr 's@.*\.(.*)\.rpm$@\1@p' |sort|uniq -c
8、统计/etc/init.d/functions文件中每个单词的出现次数,并排序(用grep和sed两种方法分别实现)
# grep -o '\<[a-zA-Z]\{2,\}\>' /etc/init.d/functions |sort |uniq -c |sort -nr
# sed -r 's/[^[:alpha:]]/\n/g' /etc/init.d/functions |sort |uniq -c |sort -nr
9、将文本文件的n和n+1行合并为一行,n为奇数行
# seq 10 | sed "1~2N;s/\n/ /"
版权声明
本文为[小灰墩墩]所创,转载请带上原文链接,感谢
https://blog.csdn.net/swyer_66/article/details/118574243
边栏推荐
猜你喜欢
关于NodeJS中JSON5的相关配置和使用
線程組ThreadGroup使用介紹+自定義線程工廠類實現ThreadFactory接口
使用开源调研工具Prophet是一种什么体验?
星界边境Starbound创意工坊订阅的mod的存放路径
云迁移的六大场景
Some experience of using dialogfragment and anti stepping pit experience (getactivity and getdialog are empty, cancelable is invalid, etc.)
更改plsql工具栏的图标大小
什么是云迁移?云迁移的四种模式分别是?
Pass in external parameters to the main function in clion
Thread group ThreadGroup uses introduction + custom thread factory class to implement threadfactory interface
随机推荐
百度笔试2022.4.12+编程题目:简单整数问题
Logging module
政务云迁移实践 北明数科使用HyperMotion云迁移产品为某政府单位实施上云迁移项目,15天内完成近百套主机迁移
grep无法重定向到文件的问题
On the multi-level certificate based on OpenSSL, the issuance and management of multi-level Ca, and two-way authentication
统信UOS卸载php7.2.24,安装php7.4.27 ;卸载再安装为PHP 7.2.34
js 递归(1)
About the configuration and use of json5 in nodejs
RecyclerView进阶使用-实现仿支付宝菜单编辑页面拖拽功能
回顾2021:如何帮助客户扫清上云最后一公里的障碍?
uni-app消息推送
RecyclerView高级使用(二)-垂直拖拽排序的简单实现
MySQL基础知识
redis数据库讲解二(redis高可用、持久化、性能管理)
倒计时1天~2022云容灾产品线上发布会即将开始
贷款市场报价利率(LPR)与贷款基准利率介绍
01-NIO基础之ByteBuffer和FileChannel
GFS分布式文件系统(理论)
Logback logger and root
man man随记和crontab的@reboot用法