The tac/comm of some simple commands in Linux

Source: Internet
Author: User

Tac

TAC is the anti-write of cat, that is, reverse-order display file contents

such as file A.txt content as follows:

12345

The TAC A.txt is printed as follows:

5
4
3
2
1

We can use awk to implement the capabilities of the TAC:

awk ' {arr[nr]=$0}end{for (count=nr;count>0;count--) print Arr[count]} ' a.txt

This is just an iteration, we can also use various loop tools (For/while) to implement the TAC command

Comm

Comm is to compare two files (two files must be in order), and output 3 columns, the first column is only the contents of the previous file, the second column is only the contents of the following file, the third column is the contents of both files

The sorting of the files can be ordered using the command sort, which is the sort a.txt

How to use: Comm file1 file2

Of course, we can also specify that a column is not displayed, such as not showing the second column (that is, only the content in the second file is not displayed), it can be written as:

Comm-2 file1 file2

Do not display the third column (that is, both files do not display), you can display as:

comm-3 file1 file2

If two or three columns are displayed, there is a space in front (actually the TAB key) and we can use TR to remove:

Comm File1 File2 | Tr-d ' \ t '

The tac/comm of some simple commands in Linux

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.