2014年10月15日 星期三

replace string in files

if we want to replace some strings in files of a folder, we can use find, xargs and sed.
for example, i want to change string '/opt/anaconda' to 'home/robot2/anaconda in many files of '/home/robot2/anaconda/bin'.
first, go to the folder
$ cd /home/robot2/anaconda/bin
then, find all files to replace the string
$ find * | xargs -i sed -i 's/\/opt\/anaconda/\/home\/robot2\/anaconda/g' {}
where '/' needs '\' to escape

沒有留言:

張貼留言