In this episode, we will discuss in factor about pipes and filters in UNIX. You can attach two commands collectively so that the output from one program becomes the input of the next program. Two or more commands associated in this way form a pipe.
To make a pipe, put a vertical bar (|) on the command line between two instructions.
When a program takes its input from another program, it performs some action on that input, and writes the result to the pattern output. It is referred to as a filter.
The grew command search a file or files for lines that have a sure pattern. The syntax is –
The name "grew" comes from the end (a UNIX line editor) command g/re/which means “globally search for a regular expression and print all lines containing it”.
A normal expression is either some plain text (a word, for instance) and/or particular characters used for pattern matching.
The simplest use of grew is to look for a pattern consisting of a particular word. It can be used in a pipe so that only those lines of the input files contain a given string are sent to the pattern output. If you don't give grew a filename to read, it reads its standard input; that's the way all filter programs work –
There are different option which you can use along with the grew command −
|S.No.||Option & Description|
Let us now use a normal expression that tells grew to find lines with "carol", followed by zero or other typescript reduced in a regular expression as ".*"), then followed by "Aug".−
Here, we are using the -I selection to have case insensitive exploration –
The sort command arranges lines of text alphabetically or numerically. The following instance sorts the lines in the food file –
The sort commands arrange lines of text alphabetically by defaulting. There are many options that control the arrangement −
More than two instructions may be linked up into a pipe. Taking a preceding pipe instance using grew, we can further sort the files adapted in August by the order of size.
The following pipe consists of the commands less, grip, and sort –
This pipe sorts all records in your directory adapted in August by the order of size, and prints them on the terminal screen. The sort option +4n skip four fields (fields are separated by blanks) then sorts the lines in numeric command.
A long output can generally be zipped by you on the screen, but if you run text during more or use the pg command as a filter; the show stops once the screen is full of text.
Let's suppose that you have a long index listing. To make it easier to study the sorted listing, pipe the output through more as follow –
The screen will fill up once the screen is full of text consisting of lines sorted by the order of the file size. At the bottom of the screen is the more prompt, where you can kind a command to move through the sort text.
Once you're completed with this screen, you can apply any of the commands listed in the discussion of the more programs.
Unix/Linux Related Interview Questions
|Perl Scripting Interview Questions||Shell Scripting Interview Questions|
|Python Interview Questions||Core Java Interview Questions|
|Linux Interview Questions||Linux Embedded systems Interview Questions|
|Red Hat Linux System Administration Interview Questions||IBM AIX Interview Questions|
|Sybase Interview Questions||IBM AIX 7 Administration Interview Questions|
|Unix Shell Scripting Interview Questions||Linux Shell Scripting Interview Questions|
Unix/Linux Related Practice Tests
|Perl Scripting Practice Tests||Shell Scripting Practice Tests|
|Python Practice Tests||Core Java Practice Tests|
|Linux Practice Tests||Linux Embedded systems Practice Tests|
|Red Hat Linux System Administration Practice Tests||IBM AIX Practice Tests|
|Sybase Practice Tests||IBM AIX 7 Administration Practice Tests|
|Autosys Practice Tests|
All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.