SED command Summary

Source: Internet
Author: User

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/72/77/wKiom1XkHTiSe4DPAACNkbOZ8S8487.jpg "title=" 11.png "alt=" Wkiom1xkhtise4dpaacnkboz8s8487.jpg "/>

Sed: A text editor for filtering and converting, primarily for line editing, one line at a time
Usage: sed "option" {script} filename
Parameters:
-N: Cancel default output
-e: For multiple edits
-I: Used to change the replacement content
-F: Directly write the SED action in a file, and-f filename to run the SED action within filename
-r:sed's actions support the syntax of extended formal notation. (The default is the basic formal French notation)

S: is a replacement
G: is all replaced
P: Print output
D: Yes delete specified, remaining output
Example: Using SEQ or echo to output a 1-30 file
# seq 1 >sed.txt
# echo {1..30}|tr "" \ n ">sed.txt

Delete:
# sed ' 1d ' sed.txt Delete first line
# sed ' $d ' sed.txt Delete last line
# sed ' 1,5d ' sed.txt delete first to fifth line

Show:
# sed-n ' 1p ' sed.txt show first line
# sed-n ' $p ' sed.txt show last line
# sed-n ' 1,5p ' sed.txt show first to fifth line

Show Lookup lines:
# sed-n '/^2/p ' sed.txt lines starting with 2
# sed-n '/2$/p ' sed.txt line ending with 2
# sed-n '/2/p ' Sed.txt contains 2 of rows

Replace:
# sed-i ' s/2/1/g ' sed.txt replace all 2 with 1
# sed-i ' 10s/10/11/g ' sed.txt specify 10th line substitution

**Use SED to remove the IP address of the NIC
# ifconfig eth0|sed-n 2p|sed ' s/^.*dr://g ' |sed ' s/bc.*$//g ' Here is the first part taken, then the latter part
# ifconfig Eth0|sed-n 2p|sed-n ' s#^.*dr:\ (. *\) BCA.*$#\1#GP ' The parentheses here must be escaped

**Replace all files with find+sed:
# Find. -type f exec sed-i ' s/2/1/g ' {} \;

# find-type F | xargs sed-i ' s/2/1/g ';


This article is from the "Shohai" blog, make sure to keep this source http://eveday.blog.51cto.com/10577430/1690216

SED command Summary

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.