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)