filter commands in unix

The grep command searches one or more files for lines containing a target and then prints all of the matching lines its finds. For example the following command prints all lines in the file “k2schools” that contains the word “schools”.

  • $grep schools k2schools

select your class in k2schools

Using grep for queries:

grep is used to search for information in structured files or simple databases. Example of such file is “Students”

$cat students

101 Veeru Java K2schools
102 Badraa SAP K2schools
103 Sanju MAINFRAMES K2schools
104 Pranav DB k2schools

This is a typical example of personnel database file. The file consists of records, each of which is terminated with a new line.a record contains several fields, seperated by a field seperator or delimitor. In this example, the field seperator is the tab character. Database files like this can be created with an ordinary UNIX system text like vi, or with a word processor.

You can use grep to find all students in the file that contains the word …

$grep java students

101 Veeru Java K2schools

Using gerp to locate files:

If you give grep two or more files to search, it it includes the name of the file before each line of output. The following command searches for lines cintaining the string “JAVA” in all of the files in the current directory.

  • $grep JAVA *

schools : 100 vinod java k2schools

k2schools: 110 rajesh java k2schools

Related Posts

You can leave a response, or trackback from your own site.

Leave a Reply

Powered by k2schools
%d bloggers like this: