Linux Learning Note 8_ the SED command of the Three Musketeers Command Review (replace)

Source: Internet
Author: User

Requirement: Replace the contents of all. sh files in the directory

Realize:


Ls/data

A.txt b.sh c.sh D.info


Method 1

-----------------------------------------------------------

See the pre-replacement content first

Find-type f-name "*.sh" |xargs Cat

Before

Before


Test replacement results, only print output when SED has no parameters

Find-type f-name "*.sh" |xargs sed ' s#before#after#g '

After

After


-I parameter to replace changes in the file

Find-type f-name "*.sh" |xargs sed-i ' s#before#after#g '


View the post-replacement content

Find-type f-name "*.sh" |xargs Cat

After

After


Note:

|xargs is understood to be a parameter (remitted to a single row) input that processes the pre-pipeline output into a subsequent command

If |cat directly, then cat will only treat the output of the pipeline as text

-----------------------------------------------------------



Method 2

-----------------------------------------------------------

Sed-i ' s#before#after#g ' find-type f-name "*.sh" '


Equivalent to:

Sed-i ' S#before#after#g '/data/b.sh/data/c.sh


Note:

The contents of the "symbol" are executed first

The symbol is the key symbol above the TAB key, which is the inverse quotation mark (? )

-----------------------------------------------------------




Linux Learning Note 8_ the SED command of the Three Musketeers Command Review (replace)

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.