标签:tr命令 config ifconf idf ons pack 单词 路径 root
案例思路
分析:使用^和|匹配出三个用户,在用cut取列。
[root@localhost data]# cat /etc/passwd |grep -E "^(root|mage|wang)"|cut -d: -f1,3,7
root:0:/bin/bash
mage:1007:/bin/bash
wang:1008:/bin/bash
案例思路
分析:用alpha匹配任何英文大小写字符,()匹配小括号。
[root@localhost data]# grep -En "^([[:alpha:]_]+)\(\)" /etc/rc.d/init.d/functions
103:checkpid() {
112:__kill_pids_term_kill_checkpids() {
138:__kill_pids_term_kill() {
187:__pids_var_run() {
223:__pids_pidof() {
230:daemon() {
324:killproc() {
407:pidfileofproc() {
422:pidofproc() {
448:status() {
524:echo_success() {
535:echo_failure() {
546:echo_passed() {
557:echo_warning() {
569:update_boot_stage() {
577:success() {
583:failure() {
591:passed() {
598:warning() {
605:action() {
618:strstr() {
624:is_ignored_file() {
650:is_true() {
660:is_false() {
670:apply_sysctl() {
案例思路
分析:[^/]+ 不在/指定范围内的字符,$匹配行尾
[root@localhost data]# echo "/etc/rc.d/init.d/functions"|grep -Eo ‘[^/]+$‘
functions
案例思路
分析:原理与上面相同
[root@localhost data]# echo "/etc/rc.d/init.d/functions"|grep -Eo ‘[^/]+‘
etc
rc.d
init.d
functions
案例思路
分析:
[root@localhost data]# last|grep ‘^root\>‘|tr -s " "|cut -d" " -f3|grep "^[[:digit:]].*$"|sort|uniq -c
4 10.0.0.110
[root@localhost data]# ifconfig|grep -E ‘\b[0-9]{1,2}\b|\b1[0-9][0-9]\b|\b2[0-4][0-9]\b|\b25[0-5]\b‘
inet 10.50.100.12 netmask 255.0.0.0 broadcast 10.255.255.255
inet6 fe80::cdf4:f8e0:5549:d25a prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:a6:5d:03 txqueuelen 1000 (Ethernet)
RX packets 63262 bytes 48344463 (46.1 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 26521 bytes 3271667 (3.1 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@localhost data]# ifconfig|grep -Eo ‘([[:digit:]]{1,3}\.){3}[[:digit:]]+‘
10.50.100.12
255.0.0.0
10.255.255.255
127.0.0.1
255.0.0.0
案例思路
分析:用tr命令先删除句子中的空格,再用‘.‘匹配任意单个字符,-o输出仅显示匹配到的字符串,最后再通过sort和uniq命令进行排序统计。
[root@localhost data]# echo "welcome to magedu linux"|tr -d ‘[[:blank:]]‘|grep -o ‘.‘|sort|uniq -c|sort -nr
3 e
2 u
2 o
2 m
2 l
1 x
1 w
1 t
1 n
1 i
1 g
1 d
1 c
1 a
标签:tr命令 config ifconf idf ons pack 单词 路径 root
原文地址:https://www.cnblogs.com/studywen/p/13440305.html