Text processing cut, sort, uniq, paste regular expressions
1 cut Extract text by column
cut -d DELIMITER -f FILEDS .example,cut -d: -f1, use- d: Colon separator, use f1 to get the first column.
[[email protected] ~]#cut /etc/passwd -d: -f 7
/bin/bash
/sbin/nologin
/sbin/nologin
/sbin/nologin
/sbin/nologin
1.2 paste -d: f1 f2 The line numbers of the two files are aligned, and -d specifies the separator, side by side.
1.3 sort sort
sort -r reverse order. sort -R random. sort -n sorts by number size. sort -f ignores string case. sort -u delete duplicate lines.
Comprehensive usage: sort -t: -k3 -n passwd -t: Specify the colon separator, -k3 is sorted according to the third column, -n is sorted according to the size of the number.
//The system generates a 12-digit random password with uppercase and lowercase letters and numbers underlined
__cat /dev/urandom |tr -dc “a-zA-Z_0-9″|head- c 12__
1.4 uniq deletes the repeated lines from the input
1.4.1 uniq -c displays the number of repeated occurrences of the line
uniq -d displays only the repeated lines Line
uniq -u only displays unique lines
//General sort list.txt |uniq -c sorts first, and then counts the number of repeated lines
2 grep command
2.1 grep -m stops after matching m times. grep -v displays unmatched lines. grep -i ignores case. grep -n displays the original line number of the match. grep -c counts the number of matched rows. grep -o only displays the matched string. grep -q Silent mode. grep -A #, matches the back # line. grep -B, matches before # lines.grep -C #, context matches each # line before and after it. grep -e or, to match multiple options. grep -e “ab” -e “cd”. grep -w matches the entire word. grep -E uses extended syntax. grep -F, only matches the string, does not support regular. grep -f file1 file2. According to the content of file1 line, match file2 line by line, you can find the same content contains in two files.
2.2 Regular expressions
2.2.1
. Any single character
[a-bA-Z0-9] A single character in the specified range< br>[^0-9] A single character outside the specified range
[:alnum:] letters and numbers
[:lower:],[:uper:],[:alpha:],[:blank: ], blank characters (spaces, pointers), [:space:], horizontal and vertical blank characters, [:cntrl:], non-printable characters, [:graph:], printable non-blank characters, [:print: ], printable non-empty, [:punct:], punctuation marks.
2.2.2 Match times
* Any number of times the preceding character.
.* ,dot, means a single character, dotted star, means a string of any length, including an empty string.
\? The preceding character 0 or 1 time
\+ The preceding character at least once
\{n\}, the preceding character n times
\{m,n\}, the preceding character at least M times, At most n times.
2.2.3 Position anchoring
^ The anchor at the beginning of the line, used to match the leftmost side of the line
$ The anchor at the end of the line, used to match the rightmost end of the line The side position
^$ matches a blank line, that is, a line without any content.
^[[:space:]]*$ A blank line can be matched to a space.
\
////For more reference man 7 regex