文本处理工具一----grep
行处理工具
[root@localhost tmp]# grep -w 'hello' passwd 精确匹配某一个单词
hello
[root@localhost tmp]# grep -o 'hello' passwd 匹配某一个
hello
hello
[root@localhost tmp]# cat passwd | grep hello
hello
helloworld
[root@localhost tmp]#
-A 后几行 -B 后几行 -C 上下文几行 -i忽略大小写 -n 打印行号
[root@localhost tmp]# grep -nB 3 '^ftp' passwd
9-mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
10-operator:x:11:0:operator:/root:/sbin/nologin
11-games:x:12:100:games:/usr/games:/sbin/nologin
12:ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
[root@localhost tmp]# grep -nA 3 '^ftp' passwd
12:ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
13-nobody:x:99:99:Nobody:/:/sbin/nologin
14-avahi-autoipd:x:170:170:Avahi IPv4LL Stack:/var/lib/avahi-autoipd:/sbin/nologin
15-systemd-bus-proxy:x:999:997:systemd Bus Proxy:/:/sbin/nologin
[root@localhost tmp]# grep -nA C '^ftp' passwd
grep: C: invalid context length argument
[root@localhost tmp]# grep -nC 3 '^ftp' passwd
9-mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
10-operator:x:11:0:operator:/root:/sbin/nologin
11-games:x:12:100:games:/usr/games:/sbin/nologin
12:ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
13-nobody:x:99:99:Nobody:/:/sbin/nologin
14-avahi-autoipd:x:170:170:Avahi IPv4LL Stack:/var/lib/avahi-autoipd:/sbin/nologin
15-systemd-bus-proxy:x:999:997:systemd Bus Proxy:/:/sbin/nologin
以什么为开头,以什么为结尾
[root@localhost tmp]# grep '^root' passwd
root:x:0:0:root:/root:/bin/bash
[root@localhost tmp]# grep 'bash$' passwd
root:x:0:0:root:/root:/bin/bash
redhat:x:1000:1000:redhat:/home/redhat:/bin/bash