The Joy of Linux commands--cat

Source: Internet
Author: User

The purpose of the cat command is to connect files or standard input and print. This command is commonly used to display the contents of a file, or to connect several files to display, or to read from a standard input and display it, often in conjunction with redirection symbols.

Command parameters:

-A,--show-all equivalent to-vet

-B,--number-nonblank number of non-null output lines

-e equivalent to-ve

-E,--show-ends displays at the end of each line

-N,--number all line numbers for the output, numbering the number of rows for all outputs starting from 1

-S,--squeeze-blank a blank line that has more than two lines in a row and is substituted for a row

-T vs.-VT equivalence

-T,--show-tabs tab shown as ^i

-U (ignored)

-V,--show-nonprinting uses ^ and M-references, except LFD and TAB

Usage examples:

Print multiple files and add line numbers

[[email protected] test]# cat-n demo_cat1.sh demo_cat2.sh      1    #/bin/bash     2          echo Hello     3    echo     World4    #/bin/Bash      5         echo Hello     6    echo world[[email protected] test]#

Remove extra blank lines

[[email protected] test]# cat-n demo_cat3.sh      1    #/bin/bash     2     echo Hello      3         4         5 -N-s      demo_cat3.sh1#/bin/bash 2                   echo Hello     3         4    Echo World

To display tabs as ^i

[email protected] test]# cat-T demo_cat1.sh #/bin/bash^Iecho helloecho World

Show Break marks

[[email protected] test]# cat-v demo_cat1.sh #/bin/bash    -v demo_cat2.sh #/bin/bash^ M    echo Hello^mecho World

Where demo_cat1.sh is edited under Linux, and Demo_cat2.sh is edited under Windows, you can see that the two operating system's break marks are different, which is why many scripts under Windows edit under the upload to Linux error reasons.

The use of cat-a more clearly see the difference between the two, DOS text file is a "\ r" as a break mark, said 16 binary is 0D 0 A. The text file under Unix is marked with \ n as a break.

[[email protected] test]# cat-a demo_cat1.sh #/bin/bash$^-a demo_cat2.sh #/bin/ bash^m$^iecho hello^m$echo world[[email protected] test]#

Expand:

The cat command can also accept standard input and print to the screen

[email protected] test]# cat <<EOF> Hello> World > eofhelloworld

or redirect standard input to a file

[email protected] test]# cat >demo.txt <<EOF> Hello> linux> eof[[ Email protected] test]# cat demo.txt hellolinux

Application in script:

[Email protected] test]# vim Demo_cat. SH #/bin/bashcat <<EOF                ****main menu*****                 [1 ] Start                 [2] Shutdown                 [3] Restart                 [4  ] exiteof

Operation Result:

sh demo_cat. SH         Main menu*****         [1] Start         [2] Shutdown         [3 ] Restart         [4] Exit

The Joy of Linux commands--cat

Related Article

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.