Text Processing tools for Linux

Source: Internet
Author: User

# #: Text Processing tool 650) this.width=650; "src=" Http://img.baidu.com/hi/jx2/j_0011.gif "alt=" J_0011.gif "/>

File View method:

Cat-n Display add line number, empty line also add line number

-B Displays the add line number, but the blank line does not add a line number

-E will display the line break information

-A will show the tap key and the line wrap position "$" means "^i" is the tap key meaning

-s compresses adjacent empty lines


Reverse display of TAC "file name" line


Reverse display of Rev column, default is read keyboard input, can redirect standard input


NL "file name" plus line number, empty line no line number is equivalent to Cat-b


More convenient to view the number of rows of files, the space down, B is upside down

-D plus description hint


Less with more, you can page up and down (PGUP,PGDN), enter is a newline, relatively good "/" can search, Q exit, can be used in conjunction with the command


Head [option] ... [File] shows the 10 lines in front of the file by default

-N "Number" or-"number" display specifies the previous rows of data

-C "number" before printing a few bytes

-Q does not print header information for a file

Generate a random password for the specified number of digits:

OpenSSL Rand-base64 30 | Head-c30


Cat/dev/urandom | TR-DC ' [: Alnum:]_ ' | Head-c20


tail [option] ... [File] Displays the following 10 lines of the file by default

-N "Number" or-"number" displays the specified following lines

The last few lines of the-F trace file are updated, followed by the "&" symbol behind the file can be run in the background does not occupy the current terminal, if the trace only see the last line can keep up with-n0

-F tracked file if deleted during monitoring, plus this option prompts the file to be deleted

Tailf similar to tail-f compared to the performance is good, when the file does not change, the file will not be accessed


Cut:[option].. [file] Removes a specific column from a file by default with the TAP key delimiter

-D Specify the delimiter after the file delimiter, and then follow the "-f[number" to display the first column after the split

--output-delimiter= Custom file Separators

If you want to take multiple columns, you can use this format: cut-d:-f1-3,7/etc/passwd Remove the first column in the/etc/passwd and the second column and the seventh column

If the file contains a non-existent symbol for another column, you can use a separate symbol as the delimiter, replacing it with the TR command

Like Df-h.

Filesystem Size used Avail use% mounted on

/dev/sda2 53G 3.5G 47G 7%/

Devtmpfs 549M 0 549M 0%/dev

Tmpfs 564M 0 564M 0%/dev/shm

Tmpfs 564M 8.2M 556M 2%/run

Tmpfs 564M 0 564M 0%/sys/fs/cgroup

/DEV/SDA1 1.1G 134M 819M 15%/boot

/dev/sda3 43G 51M 40G 1%/app

Tmpfs 113M 13k 113M 1%/run/user/42

Tmpfs 113M 0 113M 0%/run/user/0

If you want to take out the utilization of the disk, we can use the following methods

[[Email protected] ~] #df-H | GREP/DEV/SD | Tr-s ""% | cut-d%-f5

Df-h convenient for human viewing format display

GREP/DEV/SD filtering rows with/DEV/SD

Tr-s ""% compresses the space and replaces it with a percent semicolon

cut-d%-f5 the% as the file delimiter, take the 5th column

Number of characters can be used when the column is in a special alignment

-C Number of characters

df-h | Cut-c35-36


Practice:

Take out the IP address of eth0 in CENTOS6

Ifconfig eth0 | grep "inet addr" | Tr-s "": | Cut-d:-f4

Take out the IP address of ens33 in Centos7

Ifconfig Ens33 | grep "Netmask" | Tr-s "": | Cut-d:-F3


Paste-d "Custom delimiter (only single-character is a delimiter)"

Function: Merge two files horizontally, first and first row, second and second row, default to "^itap" as delimiter

-S "The first line puts all rows of the first file" "The second line puts all the rows in the second file"


Text Data statistics work:

WC: The number of rows, words, and bytes of a statistic file; can be combined with a command

-L count rows

-W statistical number of words

-C Statistics byte number

-M statistic character number

The length of the longest line in the-l file


Sort sorted; general-t-k-n | -rn are used together, and if you want to sort alphabetically, you don't have to add parameters

-T Specify delimiter

-K Sort the first column

-N Sort by number

-RN reverse ORDER by number

-U will weigh the characters that get together


Uniq: Adjacent repeating rows are compressed into one

The-c shows several of them being merged into a

-U displays only non-repeating

-D Displays only duplicate


This article from the "Linux Technology accumulation Summary" blog, reproduced please contact the author!

Text Processing tools for Linux

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.