grep and VIM usage

Source: Internet
Author: User
Tags first string expression engine egrep

grep: Text Filtering (Pattern: pattern) tool includes: grep, Egrep, fgrep (regular expression search not supported)

Usage format: grep [OPTIONS] PATTERN [FILE ...]

Patterns: Filter conditions written by regular expression characters and text characters

Various options: –color=auto: Display matching text coloring, CENTOS7 has automatically matched red

-B: Show rows that are not matched by a pattern

-I: Ignore character case-N: Show matching line number-V: Count the number of rows to match

-O: Display only matched string-Q: Silent mode, no output information

-A #-B #-C #: Displays the number of front and rear lines to which the pattern matches, after, before, and before and after the # lines

-E: Implementing a logical or relationship between multiple options grep–e ' cat '-e ' dog ' file

-e: Extended Regular expression-W: whole line matches Whole word

-f:fgrep, regular expressions are not supported

grep uses wildcards, some symbols need to be escaped, and extended regular expressions are not required, as are other functions

Extended Regular expression: Egrep supports meta-characters, wildcards, and so on, and the file name wildcard slightly different: Use egrep, escape character \ Do not need

. matches any single character [] matches any single character within the specified range

* match the preceding characters any time, including 0 greedy modes: match as long as possible
\? Match its preceding character 0 or 1 times \+ match its preceding character at least 1 times

\{m,n\} matches the preceding character at least m times, up to N times

Location anchoring:

^$: ^ Beginning anchor, $ line end anchor. Together is the meaning of empty line ^[[:space:]]*$ blank line

\b The first anchor of the word, used for the left side of the word pattern; the right side of the word pattern

\<pattern\> Match Whole Word

Grouping back references is a bit difficult to understand: the contents of the pattern matching in the grouping brackets are recorded in internal variables by the regular expression engine, which are named: \1, \2, \3, ...
Exam:egrep (string1) (string2) \1\2 \1 means referencing the first string, \2 means referencing the second string

If grep is used, the parentheses need to be escaped \ (\);

Or a logical relationship: A|b:a or B c|cat:c or cat (c|c) At:cat or cat

Vim Editor Basic knowledge:

Vim [OPTION] ...                FILE ... If the file exists, the file is opened and the content is displayed

If the file does not exist, create it when you save it for the first time after editing

Parameters can be used to understand, less than a few contacts.

Three main modes: Command mode, input mode, last line mode ESC key exit current mode , always return to command mode

Command mode conversion insert mode:

I:insert, enter at the cursor position

A:append, enter after cursor location

O: Opens a new line below the line where the current cursor is located

Uppercase I,a,o, indicating the opening of a new row at the beginning of the cursor input, the end of the cursor line, and the line

Note: The insert mode and the last line mode are not directly converted and need to be brokered via command mode,

Support locking and unlocking, like locking Linux, just don't show it, actually can enter

: Q exit: q! Force exit, discard the modifications made

: Wq Save exit: wq! Forced save exits are recommended to use these exit methods, other exit methods operate fast, dangerous

In the last line mode:

R filename reads the contents of the file into the current file

W FileName writes the current file contents to another file

!command Execute command

R!command read-in command output

Cursor jump in command mode:

H: Top m Line: page Middle row L: Bottom of page

H: Left left L: Right and Right J: down K: On (used to use the arrow keys also line) can also be word jump: W, E, b

^: Jump to the first non-whitespace character at the beginning of a line $: jump to end of row 0: jump to Beginning

G: Last line #G: Jump Specify # line GG: First line

Ctrl+f to the tail of a screen ctrl+b to the first turn a screen

DD: Delete cursor line yy: Copy cursor row p,p: Paste copied whole line, can also paste deleted characters

~: Case Substitution

There is also the Find and replace function: s/string/string2/g g: Global replacement Find the delimiter in replace/replaceable to other characters

u undo Recent Changes Press Ctrl–r to redo the final undo change

These are the basic usage, VIM is very powerful, there are many powerful features, too many, we first understand the use.

grep and VIM usage

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.