Bulk substitution of common commands in Linux vi text editing

Source: Internet
Author: User


VI This command is often used in Linux, today we will learn how to implement a string in the VI bulk replacement.

A. Total replacement in the document:

%s#abc#def#g
(Replaces all ABC in the file with Def)

For example, replace All "xwen.com" in a text file with "Xwen.net":

:%s#xwen.com#xwen.net#g

(such as the file has #, available/replace, such as:%s/xwen.com/xwen.net/g)

B. Local replacement in the file:

Replace All "ABC" in line 10 to 50 with "Def"

: 10,50s#abc#def#g
(If there is a # in the file, available/replace,:%s/abc/def/g)

If the above command adds C after G, the prompt is displayed to the user to confirm (conform) whether replacement is required before replacing.
Like what

:%S#XWEN.COM#XWEN.NET#GC

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.