replace - Optimal string replacing in files for AIX -


i need remove 40 emails several files in distribution list. 1 address might appear in different files , need removed of them. working in directory several .sh files have several lines.

i have done in couple of test files:

find . -type f -exec grep -li  address_to_find {} 2>/dev/null \; | xargs sed -i 's/address_to_remove/ /g' * 

it works fine once try in real files, takes long time , sits there. need run in different servers, main cause want optimize this.

i have tried run this:

find . -type f -name '*sh' 2>/dev/null | xargs grep address_to_find 

but return:

./filecontainingaddress.sh:address_to_find 

how add this:

awk '{print substr($0,1,10)}' 

but return me before ":"?

i can rest there, haven't found how trim part

you can use -exec predicate in find, long don't use multiple file + version, means can provide several -exec clauses each of dependent on success of previous one. style avoid construction of lists of filenames, makes more robust in face of files odd characters in names.

for example:

find . -type f -name '*sh' \      -exec grep -qi address_to_find {} \; \      -exec sed -i 's/address_to_find/ /g' {} \; 

you want provide address parameter rather having type twice, unless meant 2 instance different (address_to_find vs. address_to_remove):

clean() {   find . -type f -name '*sh' \        -exec grep -qi "$1" {} \; \        -exec sed -i "s/$1/ /g" {} \; } 

(watch out / in argument clean. i'll leave making sed more robust exercise.)


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -