• Uncategorized

About xml : How-to-delete-all-lines-containing-a-string-from-all-xml-files

Question Detail

I want to delete all lines containing string “abcfk” from all the .xml files in current directory tree.
I tried find . -name "*.xml" | xargs sed -i 's/abcfk//g'

but with this i can only replace..but not deleted the line.
Any suggestions?

Question Answer

You could do:

sed -i '/abcfk/d' $(find . -name "*.xml")

note that s/abcfk//g will leave empty lines, instead use /abcfg/d to delete lines with abcfg. Alternatively:

find . -name "*.xml" -exec sed -i '/abcfk/d' {} +

You may also like...

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.