Linux Common text Operations

Source: Internet
Author: User

Cat connection file, print to standard output device

Introduction to Grammar

Cat [OPTION] ... [FILE] ...
-a--show-all equivalent to-vet
-B Display number strip blank line
-N display number includes blank line
-E Display line terminator
-s consecutive lines of whitespace, showing one row
-T Display tab
-V uses the ^ and M-symbols, in addition to LFD and TAB.

Usage scenarios:

Show line Numbers

[Email protected] ~]# cat-n anaconda-ks.cfg

Connect to view

[Email protected] ~]# cat-n anaconda-ks.cfg/etc/hosts

Merging files

[email protected] ~]# cat T1 T2 > T3

REDIRECT Text input

[[email protected] ~]# cat << EOF
Hello World
Eof
Hello World

REDIRECT File input

[email protected] ~]# Cat < anaconda-ks.cfg

More

Show files by percentage, filter, search, and more easily read large files than cat

Parameters:

-num number of rows displayed at one time
-d prompts the user to display under the screen [press space to continue, ' Q ' to quit.], if the user presses the wrong key, then it will be displayed with the message "H ' for instructions." Instead of the beep.
-l Cancel feature that pauses when meeting special character ^l (paper feed characters)
-F Number of rows, in actual number of rows, rather than lines after word wrap (some single-line words that are too long will be extended to two or more lines)
-p do not scroll to display each page, but first clear the screen and then display the content
-c similar to-p, the difference is to display the content before clearing other old data
-S When you encounter a row that has more than two consecutive lines, replace the blank line with one line
-U does not display quotation marks (varies according to the terminal specified by the term of the environment variable)
+/pattern searches for the string before each document is displayed, and then starts displaying it after the string
+num starting from Num line
FileNames to display the contents of the document, can be the number of complex

Operation Command:

Enter down n rows, which need to be defined. Default is 1 rows
CTRL+F Scroll down one screen
Space bar scroll down one screen
Ctrl+b Back to previous screen
= Output the line number of the current line
: F output File name and line number of the current line
V Call VI Editor
command to invoke the shell and execute the command
/keyword Search Keywords
Q Exit More

Common operations:

[Email protected] ~]# more-s -20 anaconda-ks.cfg

Less

More flexible than more, the mouse can scroll forward backward, casual browsing, or lazy loading, parameter usage and more similar

Common operations:

[Email protected] ~]# less-s -20 anaconda-ks.cfg

Head

View the first few lines of a file

[Email protected] ~]# head-2 anaconda-ks.cfg

Tail

View the end of the file in a few lines, as well as the monitoring file function

Parameters:

-N Display number of rows
-F Monitoring File

Common operations

[Email protected] ~]# Tail-2 anaconda-ks.cfg
[Email protected]ost ~]# tail-f anaconda-ks.cfg

Implementation of tail based on Python to view the end of the file line function
def read_last_lines (Filename,lastlines=1): F = open (filename, ' rb ') First_line_data,first_tell = F.readline (), F.tell () F.seek (0) Seek = 0 #第一层循环判断是否为空文件 for i in F:while True:f.seek (seek,2) Curre Nt_tell = F.tell () Seek-= 1 data = F.readlines () if (First_tell = = Current_tell and not D  ATA): F.close () return ' 1 ', [First_line_data] elif (First_tell = = Current_tell and Data): if (len (data) <lastlines): Data.insert (0,first_line_data) F.clos  E () return ' 2 ', Data else:if (lastlines! = 1): if (len data) = =                        Lastlines): Return ' 3 ', Data else:if (len (data) = = 1): if (First_tell = = F.tell ()): F.close () return ' 4 ', Da                 Ta[-1:]   if (len (data) > 1): F.close () return ' 5 ', data[-1:]data = read_last_l Ines (' Test2.txt ', lastlines=10) print (data)

Not to be continued ....

Linux Common text Operations

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.