Use sed to modify files in batches

Source: Internet
Author: User

In the afternoon, I had to change some HTML images from PNG to GIF. There are about 20. If you change one by one, it is really annoying. The automation should be automated.

When thinking about how to scripted this problem, I think there is a key point in this demand: the need to modify the original file, rather than passing it in the pipeline. Ask the Google guru and ask man sed again. The answer is displayed.

1. Use the print function of sed to check before performing replacement.

$ Sed-n'/. PNG/P' C *. htm

 

2. If there is no problem, replace it.

$ Sed-I's/. PNG/. gif/'C *. htm

 

3. If you want to make a backup before performing replacement (add the. Bak extension after the original file)

$ Sed-I. Bak's/. PNG/. gif/'c2.htm

 

After Evernote is used, many of my instant scripts can be recorded. This is equivalent to a buffer zone, which first exists in the buffer zone and then blogs it out.

In the future, there will be a lot of small-space blogs to record these handy little scripts.

 

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.