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