2016-08-08
Content of the lesson:
Tools for working with the text sed
Vim Editor
Introduction to shell Script Programming basics
Sed:sed is a stream editor that processes a single line of content at a time. When processing, the currently processed rows are stored in a temporary buffer, called the pattern space,
The contents of the buffer are then processed with the SED command, and the contents of the buffer are sent to the screen after processing is completed. The original file is not edited by default, only the file copy of the schema space is processed
sed [option] ' Addresscommand ' file ....
-N: Silent mode (automatic printing of non-output mode space content)
-R: Supports extended regular expressions
-I: Original edit
-e: Multi-point editing
' Addresscommand ':
Address
#: First few lines
N,m: Rows N to M
n,$: Nth line to last row
/pattern/: Each row (regular expression) to which the pattern can be matched
Command
D: Delete
P: Print Display
A \text: Append text at the end of the line; Support for multiline append using \ n
I \text: Append text in front of line, also support using \ n to implement multiline append
s///: Find replacement, support use of other separators, [email protected]@@,s###
Replace tag:
G: In-line global substitution
P: Show the rows that were successfully replaced
W/path/to/somefile: Saving a successful replacement row to a file
Vim Editor:
Visual Edit improved
Vim [OPTION] ... FILE ...
+: Position the last line when opening a file
+#: Position in # # line when opening file
+/pattern: Immediately after opening the file, leave the cursor at the beginning of the first line that is matched to the PATTERN
–d file1 file2 ... Compare multiple Files
Vim Editing multiple files
Vim FILE1 FILE2 FILE3
: Next switches to the next file
:p Rev Switch to the previous file
: Last switch to final file
: first to switch to file one
Vim mode:
Command mode: Default mode when opening a file
Edit mode: Enter the text editing mode when entering I,i,a,a,o,o
Extended Command mode (Extended): Mode when input:
Command mode--edit mode:
I: Enter at the beginning of the current cursor
I: Enter at the current cursor position
A: At the end of the line where the cursor is located
A: Enter at the back of the cursor
O: At the beginning of the previous line of the cursor
O: At the beginning of the next line of the cursor
Insert mode----> Command mode
Esc
Command mode----> Extended mode
:
Extended mode----> Command mode
Esc
To close a file:
Extended Command mode
: Q Quit when file is not changed
: Wq Save Exit
: q! Force not save exit
: wq! Force Save exit
Command mode:
ZZ: Save exit
ZQ: Do not save exit
Cursor jumps in command mode:
Jump between characters:
H: Left L: Right J: down K: Upper
#COMMAND: Jumps the number of characters specified by #;
Jump between words:
W: The first word of the next word
E: The ending of the current or next word
B: The first word of the current or previous word
#COMMAND: Specifies the number of words to jump by # at one time
Current page Jump:
H: Top m: Page Middle row L: Bottom of page
Beginning line End Jump:
^: jumps to the first non-whitespace character at the beginning of a line;
0: Jump to the beginning of the line
$: Jump to end of line
Move between rows:
#G, extension mode: #: Jump to line specified by #
G: Last line
1G, GG: First line
Move between sentences:
): Next sentence (: Previous
Move between paragraphs:
}: Next paragraph {: Previous paragraph
Command mode operation
Character editing:
X: Delete the character at the cursor;
#x: Delete the # characters at the beginning of the cursor
XP: Swap the position of the character where the cursor is located and the character after it
~: Convert Case
Delete command:
D: Delete command, can be combined with the cursor jump character, to achieve range deletion;
DD: Delete entire row
#dd: shanchu# Line
d$: Delete to end of line
d^: Delete to non-empty header
D0: Delete to the beginning of the line
Copy command (y, yank):
Y: Copy, behaves similar to D command
YY: Copy entire row
y$
Y0
y^
Paste command (P, paste):
P: If the buffer is an entire row, paste the current cursor below the row, or paste it at the end of the current cursor.
P: If the buffer is an entire row, the current cursor is pasted above the row, otherwise, it is pasted to the front of the current cursor position.
Extended mode: Find
/pattern: Looks at the end of the file from the current cursor location
? PATTERN: Finds the file header from the current cursor location
N: Same direction as command
N: Opposite direction of command
S: Complete the Find and replace operation in extended mode
Format: s/What to look for/replace with content/modifiers
Address delimitation:
#: The specific # line, for example, 2 means line 2nd;
#,#: From the left # indicates the line start, to the right # indicates the end of the line
#,+#: The start of the line from the left #, plus the number of rows on the right # representation
: 2,+3 = 2 to 5 rows
.: When moving forward
$: Last line
., $-1 current line to penultimate line
%: Full text, equivalent to 1,$
Command mode: Undo Changes
U Undo Recent Changes
. Repeat previous action
Browsing with multiple windows
Multiple files:
Vim-o|-o FILE1 FILE2 ...
-O: Horizontal split
-O: Vertical split
Switch between windows: Ctrl+w, Arrow
Single File:
Ctrl+w,s:split, Horizontal split
Ctrl+w,v:vertical, Vertical split
Ctrl+w,q: Canceling adjacent windows
Ctrl+w,o: Cancel All windows
: Wqall exit
Shell Script Basics:
A shell script is a text file that contains some commands or declarations and conforms to a certain format
Format requirements: First line shebang mechanism
#!/bin/bash
Specification for creating shell scripts:
Shell script at the beginning of the best written on the author, date, description and other basic information, on the one hand can be convenient for others to read, on the other hand also convenient to review
#!/bin/bash#author: #Version: 1.0#description:this script Displays some information about your environment
To create a script step:
First step: Use a text editor to create a text file
The first line must include the shell declaration sequence: #!
#!/bin/bash
Add Comment
Comments start with #
Step two: Run the script
Give execute permission to specify the absolute or relative path of the script on the command line
Run the interpreter directly and run the script as a parameter of the interpreter program
#!/bin/bash#created by: #date: 2016-08-09#ver:1.0#des:test scriptecho ' date ' echo ' cal ' [[email protected] ~]# sh first.sh Tue 9 09:03:38 CST 2016August Su Mo Tu We Th Fr Sa 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
This article from the "6638225" blog, reproduced please contact the author!
Basic Linux Learning-eighth day