18.11.2012 Views

3 - Weber State University

3 - Weber State University

3 - Weber State University

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

110 Chapter 3 Exploring Linux Filesystems<br />

Keep in mind that the text being searched is case sensitive; to perform a search that is not case<br />

sensitive, use the –i option to the grep command:<br />

[root@server1 ~]# grep "algonquin park" project4<br />

[root@server1 ~]#_<br />

[root@server1 ~]# grep –i "algonquin park" project4<br />

room this year while vacationing in Algonquin Park - I<br />

I have been reading on the history of Algonquin Park but<br />

[root@server1 ~]#_<br />

Another important note to keep in mind regarding text tools such as grep is that they match<br />

only patterns of text; they are unable to discern words or phrases unless they are specified.<br />

For example, if you want to search for the lines that contain the word “we,” you can use the<br />

following grep command:<br />

[root@server1 ~]# grep "we" project4<br />

Hi there, I hope this day finds you well.<br />

Unfortunately we were not able to make it to your dining<br />

[root@server1 ~]#_<br />

However, notice from the preceding output that the first line displayed does not contain the<br />

word “we”; the word “well” contains the text pattern “we” and is displayed as a result. To<br />

display only lines that contain the word “we,” you can type the following to match the<br />

letters “we” surrounded by space characters:<br />

[root@server1 ~]# grep " we " project4<br />

Unfortunately we were not able to make it to your dining<br />

[root@server1 ~]#_<br />

All of the previous grep examples did not use regular expression metacharacters to search<br />

for text in the project4 file. Some examples of using regular expressions (see Table 3-4)<br />

when searching this file are shown throughout the remainder of this section.<br />

To view lines that contain the word “toe” or “the” or “tie,” you can enter the following<br />

command:<br />

[root@server1 ~]# grep " t.e " project4<br />

especially wished to see the model of the Highland Inn<br />

and the train station in the dining room.<br />

I have been reading on the history of Algonquin Park but<br />

no where could I find a description of where the Highland<br />

[root@server1 ~]#_<br />

To view lines that start with the word “I,” you can enter the following command:<br />

[root@server1 ~]# grep "^I " project4<br />

I have been reading on the history of Algonquin Park but<br />

I need not wait until next year when I visit your lodge?<br />

[root@server1 ~]#_<br />

© Cengage Learning. All rights reserved. No distribution allowed without express authorization.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!