shell text processing tools

A, cut

Specify the delimiter, cutting file;

Common parameters: -d (delimiter) specify the delimiter

     -f specify which column to extract

     -out-delimeter = 'xx' output by the delimiter want for their own replacement delimiters

Limitations: 1, -d can not specify a plurality of separators;

    2, can not do high-level formatted output, we need to master awk.

Example:

cut -d '' -f 1 / etc / fstab // take the first column

cut -d '' -f 1,3 / etc / fstab // get column 3

cut -d '' -f 1-3 / etc / fstab // taken columns 1-3

cut -d [:] -f 1 / etc / passwd // designated as a space or a colon delimiter

Two, sort

When sorting sort, a default view of characters (including alphanumeric, spaces, and special characters), the ASCII code ordering (not ordered according to numerical values)

Common parameters:

    -r reverse order

    -F ignores case characters

    -t DELIMITER specified field delimiter

    The first columns specified field to sort -k

    -n specify numerical values ​​are sorted

    -u uniq sort deduplication, do not show repetitive

Three, uniq

Remove duplicate content (and history, as only together content is the continuous repetition)

Common parameters:

    -c displays each line repeated many times, figured out

    -d display only duplicate rows over

    -u display not only duplicate rows

Example:

  History | cut -d' ' -f 5 | uniq
  History | cut -d' ' -f 5 | sort | uniq -c/-d/-u

 

Guess you like

Origin www.cnblogs.com/www-k/p/11348018.html