bash - Replace a string in Multiple Files Including Hidden Files? -


on mac os x, tried replace "string1" in multiple files "string2". however, there lots of hidden files such .filename_hidden

grep -rl string1 somedir/ | xargs sed -i 's/string1/string2/g' 

but here error.

grep -r apple ./ | xargs sed -i 's/apple/pear/g' sed: 1: ".//.file2:this": invalid command code . 

.file2 has

this apple hidden. still want replace pear 

i tested on ubuntu:

grep -r apple ./ | xargs sed -i 's/${apple}/${pear}/g' ./*.* sed: can't read ./*.*: no such file or directory sed: can't read ./.file2:this: no such file or directory sed: can't read is: no such file or directory sed: can't read hidden: no such file or directory sed: can't read apple: no such file or directory 

update:

adding option -l in grep command, mac os x terminal gives following:

 ~/bash_play/test_replace $grep -rl apple . ./.file2 ./file1  ~/bash_play/test_replace $grep -rl apple . | xargs sed -i 's/apple/pear/g' sed: 1: "./.file2": invalid command code .   ~/bash_play/test_replace $grep -rl apple . | xargs sed -i 's/apple/pear/g' *  sed: 1: "file1": invalid command code f  ~/bash_play/test_replace $grep -rl apple . | xargs sed -i 's/apple/pear/g' */*.* sed: 1: "*/*.*": invalid command code * 


Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -