简体   繁体   中英

How do I change the suffix of all files that contain a specific string

I want to find all *.xml files that have a particular DOCTYPE and change the suffix from .xml to .dita.

I can list the files doing this:

find . -type f -name '*.xml' -exec grep --files-with-matches '<!DOCTYPE concept PUBLIC "-//OASIS//DTD DITA' {} +

but I'm not clear about piping this into an mv command that will do the desired rename.

Inspired by Modifying replace string in xargs from @betabandido:

Try to add | xargs -n 1 -i sh -c 'echo mv $1 ${1%.xml}.dita' -- {} | xargs -n 1 -i sh -c 'echo mv $1 ${1%.xml}.dita' -- {} , if output looks OK, remove the echo , assuming sh is in fact bash since tagged with linux .

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