9.Linux command line Text Processing tool

Source: Internet
Author: User
Tags diff

9.Linux Command line Text Processing tool

• Search text grep based on keyword

· grep ' Test ' /etc/passwd keyword search,

· Find/-user Test | grep Video Search in the results, Find the output is text, and then grep keyword,

• Options: - I. , ignoring case,

-N, displays the number of rows where the result is,

-V, which displays the row that excludes the keyword,

-ax, display the keyword and the following x line,a=after,

-BX, display keywords and front x rows,b=before,

--color=auto keywords are displayed in color,


• Column-based processing of text content cut

· cut-d:-f3/etc/passwd- put passwd A colon is a delimiter that cuts a row into columns, showing the third column of each row,

· grep test/etc/passwd | cut-d:-f3 Look in the results,

· cut-c2-6/etc/passwd find each line of 2-6 the characters,

• Options: - D , specifying delimited characters ( tab is the default ) ,

-F, specify the column number of the output,

-C, delimited based on characters,

• Statistical text information WC (word count)

· WC [ option ]passwd

• Options: - L , counting only the number of rows,

-W, only the words are counted,

-C, counting only bytes,

-M, counting only the number of characters,

· sorting text content sort ,

· sort passwd display after sorting, do not change the original file order

• Options: - R , in reverse order,

-N, sorting based on numbers

-F, ignoring case

-U, delete duplicate rows

-t C, sorting columns byusing C as a delimiter

-K x, when sorting based on the specified character as a column, specifies the sort based on that column,

Uniq is used to delete adjacent duplicate rows


· compare the differences between two files diff, diff test Test1

• Options: - I. , ignoring uppercase and lowercase

-B, ignore the change in the number of spaces

-U, unified display of comparison information, commonly used to generate patch files,diff-u test test1 > Final.patch

• Processing of text content tr, Translate

· tr-d ' TMD ' < Test Delete keywords in file

· TR ' A- z "' A- z ' < The casing in the test conversion file


• Search for and replace text sed,

• Involves regular expressions, slightly


9.Linux command line Text Processing tool

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.