Shell's sed grep little memory

Source: Internet
Author: User

SED command

Use

Provides the flow editor.

Grammar

sed [-n] Script [File ...]

sed [-n] [-e Script] ... [-F ScriptFile] ... [File ...]

Describe

The SED command modifies the row from the specified File parameter according to the edit script and writes the result to standard output. The SED command contains many features for

Select the row you want to modify, and make changes only to the selected row.


(2) S/pattern/replacement/flags

Replace the first occurrence of pattern space with the replacement string


(2) y/pattern1/pattern2/

Replace the characters that appear in all PATTERN1 variables with the corresponding PATTERN2 characters. In

The number of characters in the PATTERN1 and pattern2 variables must be equal. NewLine characters are denoted by \ n.


To perform a global change, enter:

Sed "s/happy/enchanted/g" Chap1 >chap1.new

The command sequence replaces each word happy that appears in the file Chap1 with the word enchanted. It writes the edited version to the name

chap1.new separate files. S

The G character at the end of the subcommand tells the SED command to make as many substitutions as possible on each line. If there is no G character, then the SED command will only substitute

Happy the first occurrence of a word in a row.


The SED command operates as a filter. It is from a standard input or a file named in the command line (in this case

CHAP1) reads text, modifies text, and writes it to standard output. Unlike most editors, it does not replace the original file. In the water

Line is used, this makes the SED command a powerful command.


Sed-n "/food/p" chap3

SED-N displays each line in the file chap3 that contains the word food. Typically, the SED command copies each edited line to the standard output. -N Makes

Sed

command to stop doing this




If all rows that do not match the pattern are displayed, enter:

Grep-v "^#" PGM.S

This will show all lines in the PGM.S with the first letter not the # (well character).

To display all lines in the file file1 that match the ABC or XYZ string, enter:

Grep-e "ABC|XYZ" file1


If you are searching for $ (dollar sign) in a file named Test2, enter:

grep \\$ Test2

To force the shell to pass the \$ (SLR slash and dollar sign) to the grep command, you must use \ \ (double backslash). \ (SLR slash)

Characters can notify grep

command to treat subsequent characters (in this case, $) as literal characters instead of expression characters.


VI

: e! re-edits the current file and discards all changes.

: E + file Edits the specified files from the last start.

: the e + number file edits the specified file starting at the specified line.



Shell's sed grep little memory

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.