linux三剑客自用命令笔记记录

sed 

-i  直接修改文档读取的内容,不在屏幕上输出
[root@localhost home]# cat a.sh 
user=whoami
[root@localhost home]# sed -i 's#user#id#g' a.sh   ##表示查找user并替换为id,后面跟g表示一行中有多个user的时候,都替换,而不是仅替换第一个,a.sh可以加绝对路径
[root@localhost home]# cat a.sh 
id=whoami
[root@localhost home]# 

grep

[root@localhost home]# grep id -n a.sh   ###根据id查询并列出行号
1:id=whoami
[root@localhost home]# grep log -n a.sh  ###根据log查询并列出行号
2:syslog
[root@localhost home]# grep ^s -n a.sh   ##首个字符为s的查询
2:syslog
[root@localhost home]# grep g$ -n a.sh  ##以g结尾的查询行数
2:syslog
[root@localhost home]# 

专业从事搬砖多年,还是在继续搬砖中,厚积薄发~
原文地址:https://www.cnblogs.com/Crazy-Liu/p/14484654.html