1 on 1 web hosting - Sams Teach Yourself Shell Programming in 24 Hours

Sams Teach Yourself Shell Programming in 24 Hours Contents Index Hour 15: Text Filters Previous Chapter Next Chapter Sections in this Chapter: The head and tail Commands Summary Using grep Questions Counting Words Previous Section Next Section Using grep Looking for Words Line Numbers Reading From STDIN Listing Filenames Only The grep command lets you locate the lines in a file that contain a particular word or a phrase. The word grep stands for globally regular expression print. The command is derived from a feature of the original UNIX text editor, ed. To find a word in ed, the following command was used: g/word/p Here word is a regular expression. For those readers who are not familiar with regular expressions, Chapter 16, “Filtering Text Using Regular Expressions,” discusses them in detail. This particular ed command was used widely in shell scripts, thus it was factored into its own command called grep. In this section, you will look at the grep command and some of its most commonly used options. Looking for Words The basic syntax of the grep command is grep word file Here file is the name of a file in which you want to search for word. The grep command displays every line in file that contains word. When you specify more than one file, grep precedes each of the output lines with the name of the file that contains that line. As an example, the following command locates all the occurrences of the word pipe in file ch15.doc (this chapter): $ grep pipe ch15.doc I’ve broken the command into two lines, with the pipe character as the the right thing and use the next line as the command to pipe to. It’s The first few lines look like (ten actually, I piped the output to If I specify more than one file the output changes as follows: $ grep pipe ch15.doc ch15-01.doc ch15.doc:I’ve broken the command into two lines, with the pipe character as the
We highly recommend you visit web and email hosting services if you need stable and cheap web hosting platform for your web applications.

Leave a Reply