Use of the SED command under Linux

Source: Internet
Author: User

SED File processing tool Editor
Sed-i directly modify the contents of the file is not output to the terminal

Add and remove Vi:2,5del as a unit of behavior

NL (Show line number) passwd |sed ' 2,5d ' |head (tail)-N 10 No modification of source file
NL (Show line number) passwd |sed-i ' 2,5d ' |head (tail)-N 10 Modify source file
NL passwd |sed ' 2a drink tea ' |head-n 5|nl added below the second line
NL passwd |sed ' 2i drink tea ' |head-n 5|nl on the second row above

Replace
NL passwd |sed ' 2,5c No 2-5 number ' |head-n 5|nl
View Only
NL passwd |sed-n ' 2,5p ' uses-N to print only the contained rows without the-n will match and all the display
Search and display
NL passwd |sed-n '/root/p '
Delete
NL passwd |sed-n '/root/d '

Search and replace
Sed-i ' s/\.$/\/!/g ' 1.txt will end each line. Change for! Modify source file
Statistic line number
Sed-n "$=" If.txt
Wc-l If.txt | awk ' {print '} '
Sed-i ' 2s/^.*addr://' if.txt

Use of the SED command under Linux

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.