Linux [Text Processing]

Source: Internet
Author: User

Cut-divides the line into the specified fragment according to the requirements

Common parameters:

-D to ... As the delimiter-D: Split Line (similar to split in Python)

-F Gets the split column-f1-3 the 1th to 3rd column (that is, the three-in-one column, which starts at 1 instead of 0)

-c Specifies the position character-c1 to get the first character of the row

grep--Find text content

Common parameters:

-I ignores case

-N Display number of rows

-an displays the after (after) n rows of the found character

-bn shows the first (before) n rows of the found characters

-V displays lines that do not contain this character

Example:

grep Yechengzhou/Extra/PASSWD | Cut-d: f6 (get Yechengzhou user's home directory)

WC--Statistical text information

-L Line

-W Word

-M character

-C byte

The WC filename without parameters gets the result as

Number of lines word number character file name

Sort-sorts the contents of a text

Default sorted by first letter

Parameters:

-R Reverse

-n Specifies sorting based on numbers

-F ignores case

-U Delete duplicate rows (or find | Uniq can only delete adjacent duplicate rows)

-T C splits the rows into columns based on the C delimiter and sorts the columns

diff--Compare the differences between two files

-I ignores case

-B ignores changes in the number of spaces

-U Unified Display of comparison information (typically used to generate patches)

TR-Text processing, only for standard output, if you want to modify the contents of the file need to redirect

Tr-d "TMD" < filename delete the TMD output from the text and the contents of the file unchanged

TR ' ABC ' ABC < filename replaces the lowercase a,b,c in the file with A,b,c, the file content is unchanged

-S, delete all str_from repeats the sequence of characters, preserving only one, that is, repeating the string compression into a
"A very classic application is to reduce irregular spaces to a single space: tr-s ' filename '

SED--Search Replace, use regular expression processing, replace standard output

SED regular file

Example:

Sed "1,50s/linux/unix/g" filename replaces all of the 1-50 lines of Linux in filename with Unix (/g for all, no/g only replaces the first one)

sed-f sedfile filename is sed based on the contents of the Sedfile (for example, the Sedfile content is "s/linux/unix/g" so that all Linux in filename is replaced with Unix)

Sed-e "s/linux/unix/g"-E "s/windows/os/g" filename makes multiple substitutions at the same time

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.