How to sort text lines in reverse order in Linux

Source: Internet
Author: User
Linux how to arrange text lines in reverse order 1. Command method: www.2cto. comnlfilename | sort-nr | cut-f2 this method is very unix style, using multi-command combination to complete a certain function is a typical unix characteristics. Single command: In linux, the first thought is tac...
In Linux, how does one arrange text rows in reverse order? 1. command method: www.2cto.com nl filename | sort-nr | cut-f2 this method is very unix-like. Using a combination of multiple commands to complete a function is a typical unix feature. Single command: In linux, the first thought of is the tac command, which can be used to sort and output text lines in reverse order. 2. AWK method: awk '{line [NR] = $0} END {for (I = NR; I> 0; I --) print line} 'filename' utilizes the AWK array function. 3. PERL method: perl-e 'print reverse <> 'filename' unless you are familiar with PERL. 4. SED method sed '1! G; h; $! D 'filename is a classic operation. if you can understand the meaning of the sed function in this line of command, you will have a basic understanding of sed. Www.2cto.com 5. VI method vi command: g/^/m0 this method was not thought of, it is really simple and practical. 6. shell method #! /Bin/bash revread () {local line read line | return 0 revread echo $ line} revread

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.