Linux with Operating System Concepts


parts described above, we have



Download 5,65 Mb.
Pdf ko'rish
bet86/254
Sana22.07.2022
Hajmi5,65 Mb.
#840170
1   ...   82   83   84   85   86   87   88   89   ...   254
Bog'liq
Linux-with-Operating-System-Concepts-Fox-Richard-CRC-Press-2014


parts described above, we have
[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]
This gives us each of these options
• 0–9 [0–9]
• 10–99 [1–9][0–9]
• 100–199 1[0–9][0–9]
• 200–249 2[0–4][0–9]
• 250–255 25[0–5]
Now we can get back to our regular expression. The expression must express the above 
list of options, followed by a period, followed again by the list of options and a period, fol-
lowed again by the list of options and a period, followed finally by the list of options one 
more time. Thus, we want to have the list of options followed by a period occur three times 
exactly, followed by the list of options a fourth time. This can be represented as
(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}
([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])
Now our grep instruction is
egrep ‘(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|
25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4]
[0-9]|25[0-5])’/etc/*
6.4.2 Useful egrep Options
If you were to issue the previously defined egrep instruction to search for IP addresses 
among the files of /etc, you would obtain many responses. Of course the file we were look-
ing for was resolv.conf, but another file, ntp.conf would also have matching lines. Let us 
examine the output from the egrep statement. We receive output like that of Figure 6.2.


220

Linux with Operating System Concepts
Notice among the responses shown in Figure 6.1 that many files contain IP addresses 
(many of which are for localhost, 127.0.0.1) or define netmasks (we discuss netmasks in 
Chapter 12). One interesting match is for the file prelink.cache. This file is a binary file and 
really should not have matched. To ignore binary files, we add the option –I.
There are many other useful options available in grep. The option –c responds with the 
total number of matches rather than the matches themselves. If grep executes on a number 
of files, each filename is listed along with the number of matches in that file, including 0 if 
no lines in the file matched the regular expression.
The –n option will insert line numbers before the file name. If we wish to discard the 
filenames, we can use –h. The option –H forces grep to display the filenames. The option –h 
is used by default if grep is only searching a single file while –H is used by default if grep is 
searching multiple files. Figure 6.3 shows the output from the same command as shown in 
Figure 6.2, but with the –H, –I, and –n options applied.
The option –i forces egrep to ignore case. This allows you to specify letters in your regu-
lar expression without having to differentiate upper versus lower case. For instance,
egrep ‘[ABCabc]’ 
somefile
and
egrep –i ‘[abc]’ 
somefile
will accomplish the same task.
Recall the challenge of properly using 
[^…]
to denote “NOT.” A far easier solution is to 
use the –v option, which means “invert the match.” For instance, if we want to search for all 
strings that do not contain a period, we could try to write a regular expression that conveys 
this, but we could also use the command
egrep –v ‘\.’ 
somefile
networks:loopback 127.0.0.0
networks:link-local 169.254.0.0
ntp.conf:restrict 127.0.0.1
ntp.conf:#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
ntp.conf:#broadcast 192.168.1.255 autokey # broadcast server
ntp.conf:#broadcast 224.0.1.1 autokey 
# multicast server
ntp.conf:#multicastclient 224.0.1.1
# multicast client
ntp.conf:#manycastserver 239.255.254.254 # manycast server
ntp.conf:#server 127.127.1.0 # local clock
openct.conf: # 
>=
linux-2.6.27.14
openct.conf: # 
>=
linux-2.6.28.3
pam_ldap.conf:host 127.0.0.1
pam_ldap.conf:#uri ldap://127.0.0.1/
pam_ldap.conf:#uri ldaps://127.0.0.1/
Binary file prelink.cache matches
resolv.conf:nameserver 172.28.102.11
resolv.conf:nameserver 172.28.102.13
FIGURE 6.2 
Download 5,65 Mb.

Do'stlaringiz bilan baham:
1   ...   82   83   84   85   86   87   88   89   ...   254




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish