Shell and awk

Source: Internet
Author: User

Sort command, The parameter-u removes the duplicate rows in the result,-T, changes the delimiter,-N sorts by number size, and-K specifies the sorting field. eg: Sort-T:-k3n gargo. DB # sort by number in the Third Region

Sort-T:-k3nr gargo. DB # Sort the result by the number size in the Third Region.

Uniq command-C prints the number of repeated records in each line in the text.-D only displays duplicate records. Each duplicate record only appears once, and-u only displays records without duplicates. Duplicate rows removed by uniq must be consecutive duplicate rows without any text.

Join command, Text record join, eg: Join-T: -o1.1 2.1 2.2-1 3-2 1 text1 text2 connects the first domain of the second text with the third domain of the first text, and displays the first domain of the first text, the first and second fields of the second text, with the separator:

Test:

Test expression

Or [expression]

$? Determines the launch status. If the value is 0, the command runs successfully.

Num1-EQ num2 if num1 is equal to num2, the test result is 0.

Num1-ge num2 if num1 is greater than or equal to num2, the test result is 0.

And (-GT is greater than,-Le is less than or equal to,-lt is less than,-ne is not equal ),

String test string is not empty

-N string test string is not empty

-Z string to test whether the string is null

Text Operators

-D file: test whether the file is a directory.

-E file: test whether the file exists.

-F file: test whether the file is a normal file.

-R file: test whether the file process is readable.

-S file test whether the length is not 0

-X file executable,-W file writable-l file Symbolic Link

Logical operators:

! Expression if expression is false, the test result is true.

If expression1-A expression2 is both true, the test result is true.

If either expression1-O expression2 is true, the test result is true.

String processing:

Calculated length $ {# string} Or expr length $ string

Expr index $ string $ substring sub-string Index

Expr match $ string $ substring string match, no match returns 0

$ {String: Position: length} Or expr substr $ string $ position $ length to extract a string (start with the first coordinate 0 and start with 1)

$ {String # substring}: Delete the shortest substring that matches the substring at the beginning.

$ {String ## substring}: Delete the oldest string that matches the substring at the beginning.

$ {String % substring}: Delete the shortest substring matched with the substring at the end

$ {String % substring}: Delete the oldest string matching the end Of the substring.

$ {String/substring/replacement} replaces the string that matches the substring for the first time.

$ {String // substring/replacement} replaces all strings that match the substring.

Awk

Awk 'in in {FS = ":"} {if ($1 = 2 & $2 = 2) Print $0} '/etc/passwd separated by: passwd, output the row information when the first or second domain is equal to 2

Awk 'in in {FS = ","} {print NF, NR, $0} end {print filename} 'sturecord # number of fields in the current NF record, current number of NR records, filename current input file name

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.