shell programming problems (IX)

Text analysis, the number of extraction / etc / password in the shell occurring

 

Answer 1:

cat /etc/passwd | awk -F: '{if ($7!="") print $7}' | sort | uniq -c

Data / etc / passwd is based on: separated

sort is each line in the file as a unit, compared with each other.

Comparison principle is rearwardly from the first letter, sequentially comparing the value of the ASCII code, and finally output them in ascending order.

parameter:

    • -u remove duplicate lines
    • -r descending output
    • -o input to the original file (redirects only enter into a new file)
    • -n Sort by value
    • Spacers may be set back -t -k specified number of columns.
    • sort -f ignore case
    • -C Check whether the file has been sorted, out of order if the output of the first row out of order, and finally returns 1
    • -C supra, the memory is not output, and returns only 1
    • -M sorted by month
    • -b ignores the blank in front of each line all characters

 

uniq ranks check and delete text files recurring, generally used in combination with sort command

uniq can check the ranks of recurring text file

uniq [-c/d/D/u/i] [-f Fields] [-s N] [-w N] [InFile] [OutFile]

parameter:

    • -c: The number of times of repeated display row in each column side.
    • -d: display only ranks recurring, displays a row.
    • -D: show all ranks recurring, there are a few lines display a few lines.
    • -u: only shows the ranks once
    • -i: Ignore different case characters
    • -f Fields: Ignore compare the number of columns specified.
    • -s N: relatively ignored in front of N characters.
    • -w N: the contents of each row after N characters do not compare.
    • [InFile]: Specifies the sorted text file. If not specified, the data is read from the standard;
    • [OutFile]: Specifies the output file. If this option is not specified, then the content display to the standard output device (display terminal).

 

Answer 2:

cat /etc/passwd | awk -F: '{if ($7!="") print $7}' | sort | uniq -c | awk '{print $2,$1}'

Guess you like

Origin www.cnblogs.com/wanghao-boke/p/12122042.html