Summary of several operations on the table type text in the Linux command line

Source: Internet
Author: User

Working with text printed as a table type in the Linux command line

First create a file list.txt with three columns of data (name, age, occupation)

A set of data per row, different columns for each group of data, separated by a space

Tsybius Programmer
Galatea Swordsman
Gaius Unknown
Fenix Engineer
Julia Merchant
Tsybius Programmer
Tsybius Programmer
Xenia Student
Flavia Teacher
Gaius Unknown

1) Contents of output file List.txt

Cat List.txt


2) sort the contents of list.txt in alphabetical order by line

Alphabetical order from small to large

Sort List.txt

Alphabetical order from big to small

Sort-r List.txt

To specify that the second column is sorted numerically, you need to add the-N and-K two parameters

Sort-n-k2 list.txtsort-nr-k2 List.txt


3) Output non-duplicated data in the data table

Implemented through Uniq

Sort List.txt | Uniq

Now output this set of data to file Sortedlist.txt

Sort List.txt | Uniq > Sortedlist.txt

4) Number of statistics file lines

Count the number of rows for all files in the current directory, using WC

Wc-l./*


5) Take data table to specify the row, specify the column information

The use of awk and SED is required to fetch rows and columns of information

Take the first column, the third column

Cat List.txt | awk ' {print $1,$3} '

Take the second line

Cat List.txt | Sed-n ' 2p '

Take the second line to line fifth

Cat List.txt | Sed-n ' 2,5p '

Take the second and fifth lines

Cat List.txt | Sed-n ' 2p;5p '


END

Summary of several operations on the table type text in the Linux command line

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.