简体   繁体   中英

How can i update the contents of a file by replacing strings using grep and find command

I am finding XML files under particular sub directory having "responsible" word in it. Searching is working fine as shown below.

find . -name '*.xml' -exec grep -H 'responsible' {} \;

./dir1/d1.xml<responsible><></responsible>
./dir2/d2.xml<responsible><SYSTEM></responsible>
./dir3/d3.xml<responsible><SYSTEM></responsible>

... and so on.

Is there a way i can replace all occurrences of SYSTEM with blank one.

result i am looking is:

./dir1/d1.xml<responsible><></responsible>
./dir2/d2.xml<responsible><></responsible>
./dir3/d3.xml<responsible><></responsible>

我会用 perl pie

perl -p -i -e 's/<responsible><SYSTEM><\/responsible>/<responsible><><\/responsible>/'   `find ./ -name *.xml`

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM