Monday, August 13, 2012

Using exec and sed to replace string in files

1. How to unlock files:

find . -exec chflags nouchg {} \;

2. How to replace string in files:

find . */info.xml -type f -exec sed -i '' 's/<\/testcase>/<serverinfo>CQ<\/serverinfo><\/abc>/g' {} \;

3. Rename files in the folder:

find . -name "1.idea*" -exec mv '{}' '{}.idea' \;

Notes: rename all the files start with '1.idea' to append '.idea' at the file name.

No comments:

Post a Comment