2012年3月22日 星期四

some string related tips

0. replace strings for all files in a folder
find ./ | xargs grep -l "$STRING_TO_BE_REPLACED" | xargs sed -i -e "s/$STRING_TO_BE_REPLACED/$STRING_TO_REPLACE/g"

0. find files and then grep som key word
find ./ -iname '$FILE_NAMES*' | xargs grep $SEARCH_KEY_WORDS

0. find files and then remove
find ./ -iname '$FILE_NAMES*' | xargs rm -rf

0. find and push multiple files from adb
find ./ -iname *.ko  | xargs -t -i adb push {} /system/lib/modules/

0. Search multiple words in VIM
/\(kernel\|panic\);  you will search both kernel and panic at the same time

0. Copy and rename multiple filse
for i in `find ./ -iname "*file_name*"`; do cp $i `echo $i | sed "s/$STRING_TO_BE_REPLACED/$STRING_TO_REPLACE/g"`; done