Linux Basics (4) Text processing

Source: Internet
Author: User
Tags sorts

Linux commands for text processing mainly have the cat TAC tail head less more sort uniq cut tr grep sed awk

1.cat to view the contents of a file

Format

Cat file_name #查看一个文件的内容

Cat file1 file2 ... #同时连接查看多个文件的内容

Common options

-N Display Line number

-E Display line terminator #Linux下面为 $

2.tac is similar to cat, but displays the contents of the file in reverse

3.head-n file_name used to view the first n rows

4.tail-n file_name used to view the following n rows

A tip for tail command tail-f file_name

View the end of the file, do not exit, wait to display the contents of the subsequent append to this file (to monitor changes to a file, such as a log file)

5.more (front flip screen only) with less (either forward or backward) support split-screen display of the contents of the file

6.sort commands for sorting of text sort [options] filename

-N Numeric sorting

-R Descending

-T field delimiter (different from cut)

-K Sorts the keywords in that field

-U sorts the same rows once only once

-F Ignore case when sorting

7.uniq to remove duplicate rows uniq [options] FileName

-C Displays the number of times the text line repeats (this refers to two consecutive rows that are adjacent, the same two rows that do not count as the same two rows)

-D displays only duplicate rows

650) this.width=650; "Src=" Http://s1.51cto.com/wyfs02/M02/84/1E/wKioL1eF-eHzcOoUAAC1ndFJ8R4429.jpg-wh_500x0-wm_3 -wmp_4-s_2787268235.jpg "title=" uniq.jpg "alt=" Wkiol1ef-ehzcoouaac1ndfj8r4429.jpg-wh_50 "/>

8.cut is used as a text cut to display the specified field of a line under some kind of separator cut

-D: Specifies that the field delimiter is blank by default

-F: Specify the fields to display

-F 1,3

-F 1-3

Example: cut-d:-F 1/etc/passwd #显示所有的用户名

9.WC for Text statistics

-L count of rows #常用

-W statistical number of words

-C Statistics byte number

-L STATISTICS The length of the longest line

-M statistic character number

Example: How many users are currently in the system (general users + system users)

Wc-l/etc/passwd | Cut-d '-F 1

The 10.tr character conversion command is used for content to convert character set 1 to character set 2

Note: TR only supports reading input from standard input, and the modified content is output to standard output (screen)

TR Set1 Set2 #将字符集1中的字符转换成字符集2中得字符

Tr-d Set1

Example 1:cat 1.txt | tr [A-z] [a-z]

650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M01/84/1F/wKiom1eF_byC3NOBAACqOp0pGFk621.jpg-wh_500x0-wm_3 -wmp_4-s_2276133986.jpg "title=" tr.jpg "alt=" Wkiom1ef_byc3nobaacqop0pgfk621.jpg-wh_50 "/>

Example 2:cat Temp.txt | tr-d [A-za-z]

650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M01/84/1F/wKioL1eF_x6ALC5GAACpN6Oz6gc959.jpg-wh_500x0-wm_3 -wmp_4-s_3737452326.jpg "title=" tr.jpg "alt=" Wkiol1ef_x6alc5gaacpn6oz6gc959.jpg-wh_50 "/>


The commands of grep sed awk are a little bit more complicated, and later.


This article is from the "thick Product Thin Hair" blog, please make sure to keep this source http://joedlut.blog.51cto.com/6570198/1826115

Linux Basics (4) Text processing

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.