The novel idea of Pipes was introduced by M.D Mcllory in June 1972– version 2, 10 UNIX installations. Piping is used to give the output of one command (written on LHS) as input to another command (written on RHS). Commands are piped together using vertical bar “ | ” symbol.
command 1|command 2
- Input: ls|more
- Output: more command takes input from ls command and appends it to the standard output. It displays as many files that fit on the screen and highlighted more at the bottom of the screen. To see the next screen hit enter or space bar to move one line at a time or one screen at a time respectively.
In UNIX/Linux, filters are the set of commands that take input from standard input stream i.e. stdin, perform some operations and write output to standard output stream i.e. stdout. The stdin and stdout can be managed as per preferences using redirection and pipes. Common filter commands are: grep, more, sort.
1. grep Command:It is a pattern or expression matching command. It searches for a pattern or regular expression that matches in files or directories and then prints found matches.
$grep[options] "pattern to be matched" filename
Input : $grep 'hello' ist_file.txt Output : searches hello in the ist_file.txt and outputs/returns the lines containing 'hello'.
The Options in grep command are:
Grep command can also be used with meta-characters:
Input : $grep 'hello' * Output : it searches for hello in all the files and directories.
* is a meta-character and returns matching 0 or more preceding characters
2. sort Command: It is a data manipulation command that sorts or merges lines in a file by specified fields. In other words it sorts lines of text alphabetically or numerically, default sorting is alphabetical.
The options include:
$sort fruits.txt $sort -n grades.txt
3. more Command: It is used to customize the displaying contents of file. It displays the text file contents on the terminal with paging controls. Following key controls are used:
- To display next line, press the enter key
- To bring up next screen, press spacebar
- To move to the next file, press n
- To quit, press q.
cat fruits.txt | more
While using more command, the bottom of the screen contains more prompt where commands are entered to move through the text.
- Filters in Linux
- AngularJS | Filters
- How to add a PHP page to WordPress?
- How to get button toggle state within HTML?
- How to set div with left image and button at bottom using bootstrap?
- Dummy Variables in R Programming
- Introduction to Machine Learning in R
- Types of Functions in R Programming
- Introduction of Light Fidelity (Li-Fi)
- Packages in R Programming
- Highlight the minimum value in each column In Pandas
- Condition Handling in R Programming
- How to put the text inside of a created icon?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.