Odd Sed Error Message

bash-3.2$ sed -i.bakkk -e "s#/sa/#/he/#g" .*
sed: .: in-place editing only works for regular files

I am trying to replace every / sa / with / he / in every dot file in a folder. How can I make it work?

+3
source share
3 answers

Use find -type fto find only files matching the name .*and exclude directories .and ... -maxdepth 1prevents return findto subdirectories. Then you can use -execto execute commands sedusing {}the placeholder, to tell findwhere should be the names of the files.

find . -type f -maxdepth 1 -name '.*' -exec sed -i.bakkk -e "s#/sa/#/he/#g" {} +

-exec xargs, , — , "foo bar\nfile" . find -print0 | xargs -0

find . -type f -maxdepth 1 -name '.*' -print0 | xargs -0 sed -i.bakkk -e "s#/sa/#/he/#g"

. , , , (, , 99% ).

+7

:

sed -i.bakkk -e "s#/sa/#/he/#g"  `find .* -type f -maxdepth 0 -print`

(,.elm,.pine,.mozilla), . ... , , .

+2

glob .* . .., , , . , :

sed -i.bakkk -e "s$/sa/#/he/#g" $(ls -d .* | grep -v '^\.\|\.\.$')
+1

Source: https://habr.com/ru/post/1713499/


All Articles