Some files edited by Ed in Linux (found on the Internet)

Source: Internet
Author: User
Tags printable characters

Basic applications:
1, $ n print the file content and add row number information
N to row n (n is a number)
N displays the content of the current row (N is a character)
D. Delete the row.
/XX/find xx
? XX? Reverse lookup xx
// Find the next
S/str1/str2/replace str1 with str2 in the current row
NS/str1/str2/replace str1 with str2 in line N
A, C, I operate on the current row (A: Add C after the row: Modify the row content I: Insert before the row)
Command parameters:
Ed File
When an error occurs, H provides simple help information, H provides detailed help information, uses a, c, and I to enter the input mode, uses it on a separate line, and returns to the command format to save the file W. WQ = x
P. P displays the current row
= Display the row number of the current row
NP displays row n
1, 6 p show 1-6 rows
$ P display the last line
1, $ P show all rows
+ Display the next row
-Display the previous line
N displays the current row and row number
Nn displays row N and row number
X and YN Show x-y rows and row numbers
L display the current row with non-printable characters
D. Delete the current row.
U cancel the last command
S/str1/str2 replace str1 with str2
S/str1 // Delete str1
Change str1 of 2 S/str1/str2/N 2nd rows to str2 and display the modified rows.
S/str1/str2/g replacement
<First>, <End> m <line>
2, 4m6 move the 2-4 rows to the end of the 6th rows
The T-block copy format is the same as that of M.
R file: after reading the file to the current row
<First>, <End> W file write block to file
! Run the shell command in cmd.
/Mode/forward query command
? Mode? Reverse lookup command
// Continue to find 2nd
G/The/P
G/The/S/The/that/searches for the whole process and replaces
V is opposite to G commands
V/The/N full search does not contain the and display
No character
^ Indicates the beginning and end of the first $ line. Any character * any number of characters identical to the previous one
/.... B/any of the three in the middle ending with a switch B
1st. S/./. Current row
2nd characters. Any character
3rd characters
S/XX */y/replace 2 or more X with Y
S/x * Y/y/replace all characters starting with X with Y
& Indicates the content of 1st Modes
/Mode 1/(mode 1)/=/mode 1 /(&)/
[Xz] indicates X or Z.
[0-9] indicates any number of 0-9.

Bytes ----------------------------------------------------------------------------------------------

The Ed editor is the simplest text editor in Linux. It is an editor that edits a file in units of action, not an editor in a MS-DOS system that edits the file in units of the entire screen frame. Therefore, if you are used to the editor of the edit style, it may take some time for you to get used to the Ed style. But this is not important, because the simplicity of Ed can make you get started quickly.

The calling of the Ed editor is very simple. If you want to create a new file, you only need to press ed in the command line window and then press the Enter key:

[Titan @ localhost Titan] $ ed <-

If you want to edit an existing file, you only need to leave one blank behind the Ed file and enter the file name:

[Titan @ localhost Titan] $ ed filename <-

After activating the Ed command, it enters the command line status of the ed Editor, which may make some beginners not used to it. If you enter some content at this time, the system will return ?, Indicates that you do not know what task to execute:

[Titan @ localhost Titan] $ ed <-

ABCDE <-

?

At this time, you need to specify several editor commands, which are:

A-add new content at the end of the file

I-Insert new content before the last row of the file

O-Replace the last line (whether existing or inserted) of the input file with the new content.

.-Exit the editing file mode and enter the command line mode (Note: The Ed editor is not exited at this time)

W-save the file

Q-exit the Ed Editor

The following is an example of several commands.

[Titan @ localhost Titan] $ ed <-activate ed command

A <-tell Ed that I want to edit the new file

My name is Titan. <-enter the content of the first line.

And I love Perl very much. <-enter the second line of content

. <-Return the command line status of ED

I <-tell Ed that I want to insert content before the last line

I am 24. <-insert "I am 24." between "My Name Is Titan." and "and I love Perl very much ."

. <-Return the command line status of ED

C <-tell Ed that I want to replace the last input line

I am 24 years old. <-Replace "I am 24." with "I am 24 years old." (Note: The last input is replaced here)

. <-Return the command line status of ED

W readme. Text <-name the file "readme. Text" and save it. (Note: If you are editing an existing file, you only need to enter W)

Q <-exit the Ed editor completely

[Titan @ localhost Titan] $ return the command line status to the Linux System

The content of this file is:

[Titan @ localhost Titan] $ cat readme. Text <-

My name is Titan.

I am 24 years old.

And I love Perl vrey much.

[Titan @ localhost Titan] $

 

Related Article

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.