Find and replcae across multiple files in linux

I have been looking a better way to replace certain string in a file accross many folders under one directory and come up with two sultions.

$ find . -name "*.html" -print | xargs sed -i 's/base_site.html/base.html/g'
$ grep -lir "base.html" * | xargs sed -i 's/base.html/base_site.html/g'

The differences are find-- looking for files based on the file names, means it only modifies certain type of file

                                grep-- looking for files based on the content of the file, any files contains "base.html" string will be replaced.

 

No comments:

Post a Comment

Datatable static image not found on the server

When you use ```datatables.min.css``` and ```datatables.min.js``` locally, instead of datatables CDN, you may have encountered that ```sort...