sort
The sort command sorts the lines in the file specified by the File parameter and writes the result to standard output. If the File parameter specifies more than one file, the sort command concatenates the files and sorts them as one file.
sort syntax
[root@www ~]# sort [-fbMnrtuk] [file or stdin]Options and parameters:
-f : ignore case Differences, such as A and a are treated as the same encoding; -b: ignore the leading space character portion; -M: sort by month name, such as JAN, DEC, etc.; -n : use "pure numbers" Sorting (default is sorted by text type); -r: reverse sorting; -u: is uniq, only one line is represented in the same data; -t : separator, default is [tab] The key is used to separate; -k : the meaning of sorting by that fieldSorting the account of /etc/passwd
[root@www ~]# cat /etc/passwd | Sortadm:x:3:4:adm:/var/adm:/sbin/nologin apache:x:48:48:Apache:/var/www:/sbin/nologin bin:x:1:1: Bin:/bin:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbin/nologin
sort is sorted by default with the first data, and the default is in string form To sort, so sort by ascending alphabet a.
The contents of /etc/passwd are separated by :, I want to sort by the third column:
[root@www ~]# cat /etc/passwd | Sort -t ':' -k 3root:x:0:0:root:/root:/bin/bash uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin Operator:x:11:0:operator:/root:/sbin/nologin bin:x:1:1:bin:/bin:/sbin/nologin games:x:12:100:games:/usr/games:/Sbin/nologin
The default is to sort by string, if you want to sort by number:
cat /etc/passwd | Sort -t ':' -k 3nroot:x:0:0:root:/root:/bin/bash daemon:x:1:1:daemon:/usr/sbin:/bin/sh bin: x:2:2:bin:/bin:/bin/sh
The default is ascending sort. If you want to sort in reverse order, the following
cat /etc/passwd | Sort -t ':' -k 3nrnobody:x:65534:65534:nobody:/nonexistent:/bin/sh ntp:x:106:113::/home/ntp:/bin/false messagebus:x :105:109::/var/run/dbus:/bin/false sshd:x:104:65534::/var/run/sshd:/usr/sbin/nologin
cat /etc/passwd | Sort -t':' -k 6.2,6.4 -k 1rsync:x:4:65534:sync:/bin:/bin/sync proxy:x:13:13:proxy:/bin:/bin/Sh bin:x:2:2:bin:/bin:/bin/sh sys:x:3:3:sys:/dev:/bin/sh
uniq
uniq command You can remove duplicate lines from sorted files, so uniq is often used with sort. That is, in order for uniq to work, all duplicate rows must be contiguous.
uniq syntax
[root@www ~]# uniq [-icu]Options and parameters:
-i : ignore the difference between upper and lower case characters; c : Counting -u : only shows the unique lineThe contents of the testfile are as follows
cat testfilehello world friend hello world hello
directly delete unsorted files, Will find that no rows are deleted
uniq testfilehello world friend hello world hello
Sort files, default is to re-
cat words | Sort | Uniqfriend hello world
Delete duplicate rows after sorting, and output the number of times the row is repeated at the beginning of the line
sort testfile | Uniq -c1 friend 3 hello 2 world
Show only the number of duplicate rows and show the number of iterations at the beginning of the line
sort testfile | Uniq -dc3 hello 2 world
Show only rows that are not duplicate
sort testfile | Uniq -ufriend
cut
The cut command extracts text columns from a text file or text stream.
cut syntax
[root@www ~]# cut -d' separator character ' -f fields <==for specific separator characters [root@www ~]# cut - c Character interval <== for neatly arranged informationOptions and parameters:
-d : followed by a separator character. Used with -f; -f : Splits a piece of information into segments according to the separator character of -d, and extracts the meaning of the first paragraph with -f; -c : takes a fixed character range in units of characters;The PATH variable is as follows
[root@www ~]# echo $PATH/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/X11R6/bin: /usr/games# 1 | 2 | 3 | 4 | 5 | 6 | 7Take the PATH variable and I will find the fifth path.
echo $PATH | Cut -d ':' -f 5/usr/local/binTake the PATH variable and I will find the third and fifth paths.
echo $PATH | Cut -d ':' -f 3,5/sbin:/usr/local/binTake the PATH variable and I will find the third to last path.
echo $PATH | Cut -d ':' -f 3-/sbin:/usr/sbin:/usr/local/bin:/usr/X11R6/bin:/usr/gamesTake the PATH variable, I want to find the first To the third, there is a fifth path.
echo $PATH | Cut -d ':' -f 1-3,5/bin:/usr/bin:/sbin:/usr/local/binwc
How many words and how many lines are in the statistics file? How many characters.
wc syntax
[root@www ~]# wc [-lwm]Options and parameters:
-l : list only rows; -w : Only how many words (English words) are listed; -m : How many characters;Use wc statistics by default /etc/passwd
wc /etc/passwd40 45 1719 /etc/passwd40 is OK Number, 45 is the number of words, 1719 is the number of bytes
The command of wc is relatively simple to use, each parameter is used as follows:
wc -l /etc/passwd #Statistic line number, in For the number of records, it is very common 40 /etc/passwd # indicates that the system has 40 accounts wc -w /etc/passwd #Statistics word occurrences 45 /etc/passwdwc -m /etc/passwd #Bytes of statistics file 1719
Speaking of the easiest way to install the system is to find a system installation CD and then slowl
Keepalived is a high-availability WEB service based on VRRP protocol, which can be used to avoid sin
A system, we can not have only one user, so we need to create other users. This is especially true a
Ubuntu installed Sogou Chinese input method
What are the Linux file management and bash features?
Exit command--Linux command application big dictionary 729 command interpretation
Linuxbond configuration steps, seven bond mode descriptions
Static library generation and use under Linux
Linux practical skills: use ntfs-3g mount ntfs equipment
Adobe Photoshop Lightroom 5 Chinese Edition Installation Tutorial
A new tool to crack the Windows 7 activation mechanism
Win10 boot entry setting method summary
Why can't the webpage be opened? Reasons and solutions for the webpage not being able to open
Two tips for quickly resetting Win8 Task Manager
Xp coup system file repair method
How to set WiFi security key in Win7 system
Integrate multiple Win 7 themed wallpapers together
Experience the WP8 graphic tutorial in Win8
Dual graphics card notebook win7 system to detect the problem of discrete graphics card