In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces "how to use linux shell pipe command and shell redirection difference", in daily operation, I believe many people in how to use linux shell pipe command and shell redirection difference problems have doubts, small make up consult all kinds of information, sort out simple and easy to use operation method, hope to answer everyone "how to use linux shell pipe command and shell redirection difference" doubts helpful! Next, please follow the small series to learn together!
The pipe command operator is: "|", it can only process the correct output information sent through the previous instruction, that is, the standard output information, for stdandard
Error information has no direct processing capability. Then, pass it on to the next command as standard input.
Pipeline command instructions:
First look at the following picture:
Command1 is output correctly as input to command2 and comand2 is output as input to comand3 and comand3 is output directly to the screen.
After passing through pipes: correct output of comand1,comand2 does not appear on screen
Note:
1. Pipeline command only processes the correct output of the previous command, and does not process the wrong output.
2. The command on the right side of the pipeline command must be able to receive standard input stream commands.
Examples:
[chengmo@centos5 shell]$ cat test.sh | grep -n 'echo'5: echo "very good! ";7: echo "good! ";9: echo "pass! ";11: echo "no pass! ";#Read the contents of test.sh file and pipe it to grep as input [chengmo@centos5 shell]$ cat test.sh test1.sh|grep -n 'echo'cat: test1.sh: no that file or directory 5: echo "very good! ";7: echo "good! ";9: echo "pass! ";11: echo "no pass! ";#cat test1.sh does not exist, error output is printed to screen, correct output is sent to grep via pipeline [chengmo@centos5 shell]$ cat test.sh test1.sh 2>/dev/null | grep -n 'echo' 5: echo "very good! ";7: echo "good! ";9: echo "pass! ";11: echo "no pass! ";#redirect test1.sh not found error output to/dev/null file, correct output is piped to grep [chengmo@centos5 shell]$ cat test.sh| lscatfile httprequest.txt secure test testfdread.sh testpipe.sh testsh.sh testwhile2.shenvcron.txt python sh testcase.sh testfor2.sh testselect.sh test.txt text.txtenv.txt release sms testcronenv.sh testfor.sh test.sh testwhile1.sh #reads the contents of test.sh and sends it to ls command through pipeline. Since ls does not support standard input, the data is discarded.
Here is an example of how to verify the above two points. Only commands that accept standard input can be used as the right side of the pipeline. Otherwise, the data will be discarded in the process of transmission. Commonly used as a pipeline command to receive data are sed,awk,cut,head,top,less,more,wc,join,sort,split, etc., all of which are text processing commands.
Pipeline commands differ from redirects
The difference is:
1. The command on the left should have standard output| The command on the right should accept standard input
The command on the left should have standard output> The command on the right can only be files
The command on the left should require standard input 2. The pipeline triggers two child processes to execute "|"programs on both sides; redirects are performed within a process These are summarized online a lot, in fact, as long as more clear usage, there must be a different description of their own. Examples: #Transformable cases #Input redirect [chengmo@centos5 shell]$ cat test.sh| grep -n 'echo'5: echo "very good! ";7: echo "good! ";9: echo "pass! ";11: echo "no pass! ";#"|"Both sides of the pipe must be shell commands [chengmo@centos5 shell]$ grep -n 'echo'
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.