Link to home
Start Free TrialLog in
Avatar of jkavx
jkavx

asked on

Replace text in files under directory

I need to replace all instances of a sourced property file in all folders under a given directory.
so every instance of
. ~/abc/app_props.sh
replaced with
. ~/abc/app-props.sh

under ~/bin

Not sure how to do this.
Avatar of woolmilkporc
woolmilkporc
Flag of Germany image

find ~/bin -type f | xargs -I{} sed -i 's#. ~/abc/app_props.sh#. ~/abc/app-props.sh#' {}

The above works if your sed implementation supports substitute-in-place ( -i ).

If your sed doesn't support it do

find ~/bin -type f | while read file; do
    sed  's#. ~/abc/app_props.sh#. ~/abc/app-props.sh#' $file > $file.$$
    mv $file.$$ $file
done


wmp
ASKER CERTIFIED SOLUTION
Avatar of woolmilkporc
woolmilkporc
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial