Вы находитесь на странице: 1из 2

LAB1:

GREP
Purpose: Show how to use grep.
Procedure:
Create grepfile.grep with the following content:
[cati@centos6 ~]$ cat grepfile.grep
alfabet
bbb
vad pe masa mere bbbune
10.23.14.66
www.example.eu
bbb
bbb
bbb
Search for a string:
[cati@centos6 ~]$ grep "bbb" grepfile.grep
bbb
vad pe masa mere bbbune
bbb
bbb
bbb
Search for a string. Line numbers displayed.
[cati@centos6 ~]$ grep -n "bbb" grepfile.grep
2:bbb
3:vad pe masa mere bbbune
7:bbb
9:bbb
10:bbb
Search for lines without string. Line numbers displayed also.
[cati@centos6 ~]$ grep -vn "bbb" grepfile.grep
1:alfabet
4:10.23.14.66
5:www.example.eu
6:

8:
11:
Grep an ip address:
[cati@centos6 ~]$ grep '^[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[09]\{1,3\}$' grepfile.grep
10.23.14.66
Grep exact word:
[cati@centos6 ~]$ grep -w "bbb" grepfile.grep
bbb
bbb
bbb
bbb
Try also the i option.

Вам также может понравиться