linux--sed use

Source: Internet
Author: User

Sed: Character Stream editor

Function: Complete a series of editing work on multiple files

Related content: Apply regular expression syntax, interact with the shell, script

Sed is the row editor. The corresponding very familiar full-screen editor is VI

Using the row editor, you can process one row at a time,

For example: $ ed test will display the last line, p shows the current line, if you want to do the subsequent operation of the row, you need to move to the corresponding row, directly enter the corresponding row of the number num, in the input of the corresponding command to operate;

For example: Delete 15 rows of data, then proceed to D;

You can also use a Tut expression as an address, such as deleting a line containing the word "regular", which you can use:/regular/d

The substitution syntax is: "Address" s/pattern/replacement/flag--pattern is a regular expression, replace the matching string in the regular expression with replacement, for example: s/regular/complex/, If the current row appears more than once, the character g:s/regular/complex/g is required, and if you want to apply it to all rows you need to place a g:g/address/regular/complex/g in front of the address;

The syntax of the SED command line:

Commond [Options] Script filename-script specifies the instruction to execute, if it contains spaces or any characters (such as $ and *) that can be interpreted by the shell, then it must be enclosed in single quotation marks;

Command: The Sed-f-F option allows you to specify the name of the script file, in the SED operation, each program reads an input line from the input file each time, generates a backup of the input row, and executes a script-specified instruction on the backup line, so changes to the input line do not affect the actual input file Therefore, only the output from the redirected sed can be captured in another program to capture the output from the file.

For example: $ sed-f sedscr list > NewList be careful not to redirect the file output to the file that is being compared to the Apache machine, otherwise it will be garbled;

The default operation for SED outputs each input line. The-n option prevents automatic output. When this option is specified, each instruction to generate output must contain the print command p

SED-E Edit the subsequent instruction sed-f follow the file name in the script Sed-n block the automatic output of the input line sed-i modify the original file

linux--sed use

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.