redirection, Piping and TR command details

Source: Internet
Author: User

I. Three kinds of I/O devices

    1. Standard input (STDIN) accepts keyboard input

      REDIRECT Single-line standard input with <

      650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/85/4E/wKioL1ef7f-z5FZyAAAJ6nUO3zs833.png "title=" 1.png " alt= "Wkiol1ef7f-z5fzyaaaj6nuo3zs833.png"/>

      redirect Multiple lines of standard input with << stop Word to customize the end symbol



      650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M01/85/4F/wKiom1ef8LiiNGDcAAALwfSvLAY855.png "style=" float: none; "title=" 2.png "alt=" Wkiom1ef8liingdcaaalwfsvlay855.png "/>



650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/85/4F/wKioL1ef8SqjiG53AAAfNEdjGDU554.png "title=" 3.png " alt= "Wkiol1ef8sqjig53aaafnedjgdu554.png"/>

2. Standard output (STDOUT) default output to Terminal

1> file redirection to File

1>>file Append to File

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M02/85/4F/wKioL1ef84OwJLhnAAAMJVDXHt4436.png "title=" 4.png " alt= "Wkiol1ef84owjlhnaaamjvdxht4436.png"/>

3. Standard error Output (STDERR) default output to Terminal

2>file Redirect to File

2>>file Append to File

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/85/4F/wKioL1ef9IvSRa_yAAANFLmmjDs545.png "title=" 6.png " alt= "Wkiol1ef9ivsra_yaaanflmmjds545.png"/>

4. Error output and correct output to the same file

&> redirection

&>> Append to

cmd > Path to Fileout 2>&1

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/85/4F/wKiom1ef9VGhHENQAAAJYugh7Hc241.png "title=" 7.png " alt= "Wkiom1ef9vghhenqaaajyugh7hc241.png"/>

5.set-c Forbidden overrides can be appended with "|>" to force overrides

Set +C allows overwriting

The 6.tee command allows the stdout to be exported to the terminal and saved to a file.

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M00/85/4F/wKioL1ef9z6yReCWAAAJyZfr7JM700.png "title=" 9.png " alt= "Wkiol1ef9z6yrecwaaajyzfr7jm700.png"/>

Two. The use of TR command detailed

tr [OPTION]...SET1 [Set2]

-C using Set1 's complement set

-D Delete the character set in Set1

-S Delete Duplicates

-T converts the set1 corresponding character to the Set2 corresponding character (the corresponding conversion, without remaining unchanged)


650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/85/50/wKioL1ef-xbxw3v9AAARWlZTojQ747.png "title=" 16.png "alt=" Wkiol1ef-xbxw3v9aaarwlztojq747.png "/>

Three. Points for use of piping

    1. Pipeline commands can only accept standard correct output (with "2>&1" to implement error output to pipeline command)

      650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/85/50/wKioL1ef_CiANIzNAAAMFOXI-JA221.png "title=" 14.png "alt=" Wkiol1ef_cianiznaaamfoxi-ja221.png "/>

    2. Common pipe commands have head tail more less TR

Four. Job

650) this.width=650; "style=" WIDTH:500PX;HEIGHT:299PX; "src=" http://s4.51cto.com/wyfs02/M00/85/50/wKioL1ef_ Pfrrz5oaakhgrbu2du660.png "title=" 1.png "alt=" wkiol1ef_pfrrz5oaakhgrbu2du660.png "border=" 0 "height=" 299 "hspace=" 0 "vspace=" 0 "width="/>

    1. Tr ' A-Z ' A-Z ' >/tmp/issue.out </etc/issue

      650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/85/50/wKioL1ef_mPgBL3OAAAI0EIWOcM379.png "title=" 2.png " alt= "Wkiol1ef_mpgbl3oaaai0eiwocm379.png"/>

    2. Echo ' Who ' | Tr ' A-Z ' A-Z ' >/tmp/who.out

      650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M00/85/50/wKioL1ef_w6jegWXAAAIQv8TJyw308.png "title=" 3.png " alt= "Wkiol1ef_w6jegwxaaaiqv8tjyw308.png"/>

    3. Mail-s "Help" root << end

      650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M02/85/50/wKioL1egAFzhMTNgAAAHHsQ1rhQ289.png "title=" 4.png " alt= "Wkiol1egafzhmtngaaahhsq1rhq289.png"/>

4. ls/root/| Tr ' \ n '
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/85/55/wKiom1egP6WDYgvtAAAJCcYSE4c829.png "title=" 5.png " alt= "Wkiom1egp6wdygvtaaajccyse4c829.png"/>

When converting to a space, enclose the space in quotation marks

5. cat File | Tr ' + ' |BC

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M00/85/54/wKioL1egQNOyP99KAAAF_QnmBvg980.png "title=" 6.png " alt= "Wkiol1egqnoyp99kaaaf_qnmbvg980.png"/>

Be careful not to have extra spaces

6.

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/85/55/wKioL1egQtGChsjIAAARl_GYfoM160.png "title=" 7.png " alt= "Wkiol1egqtgchsjiaaarl_gyfom160.png"/>

By comparing or viewing the Ascci code table to know the ^m corresponding wildcard character \ r

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/85/55/wKiom1egQ0zD5HB9AAAFkR5PvZA599.png "title=" 8.png " alt= "Wkiom1egq0zd5hb9aaafkr5pvza599.png"/>

7.

8.echo $PATH | Tr ': ' \ n '

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M02/85/55/wKiom1egRKLgEjPPAAAMxSo5E6Y106.png "title=" 1.png " alt= "Wkiom1egrklgejppaaamxso5e6y106.png"/>

9. cat File | Tr-s ' \ n '

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/85/55/wKiom1egRTTBPndqAAAIgb-ReGY452.png "title=" 2.png " alt= "Wkiom1egrttbpndqaaaigb-regy452.png"/>

10.cat File | Tr-s ' \ n ' | Tr ' \ n '



This article is from the "Hello" blog, so be sure to keep this source http://tianzhi.blog.51cto.com/11880607/1833557

redirection, Piping and TR command details

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.