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.
- AngularJS | Filters
- Filters in Linux
- Difference between node.js require and ES6 import and export
- How to select and upload multiple files with HTML and PHP, using HTTP POST?
- What are the differences and Similarities Between Lumen and Laravel?
- Getting System and Process Information Using C Programming and Shell in Linux
- Getting the current date and time with timestamp in local and other timezones in Golang
- Difference Between Single and Double Quotes in Shell Script and Linux
- Class 8 RD Sharma Solutions - Chapter 21 Mensuration II (Volumes and Surface Areas of a Cuboid and a Cube) - Exercise 21.1 | Set 1
- Difference Between DOS and Windows
- Terminal Mail and Linux Security Mail
- Zombie Processes and their Prevention
- Initializing and Cache Mechanism in Linux Kernel
- Reset a lost Linux administrative password and Explanation
- dup() and dup2() Linux system call
- mindepth and maxdepth in Linux find() command for limiting search to a specific directory.
- Network configuration and trouble shooting commands in Linux
- Introduction to Linux Shell and Shell Scripting
- Operations on Audio/Video files using ffmpeg, avconv, and youtube-dl
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.