I see this discussion: How does one find and replace text in all open files with geany?

I want to find and replace all files in a directory. The method suggested in the answer, is very good to find. Now I need to open all found files and use Geany. If the files are hundreds it's not possible to by clicking on the link in Geany.

How to do automatically?


While not an answer specific to Geany, could you do this instead using sed at the command line?

This will recursively replace "foo" with "bar" in a directory.

find . -type f | xargs -i sed -i -e "s/foo/bar/g" "{}"

| improve this answer | |
  • And I have to replace "bau/foo/" with "bea/bar/roo"? How can I write well it? Thanks – SPS Jun 3 '13 at 19:32
  • In the part "s/foo/bar/g" it means "Substitute (s) 'foo' with 'bar', on every line (g)" so! If you have a file that has the word "cat" and you want to replace it with dog, the whole line would look like: find . -type f | xargs -i sed -i -e "s/cat/dog/g" "{}" – dougBTV Jun 3 '13 at 20:44
  • 1
    @SPS There are two ways. You can put a backslash before the slash to indicate that it's to be interpreted literally, as in sed -e 's/bau\/foo\//bea\/bar\/roo/g'. Or you can use a different character as the separator instead of slash, e.g. sed -e 's~bau/foo/~bea/bar/roo~g'. – Gilles 'SO- stop being evil' Jun 3 '13 at 22:25
  • Thanks @Gilles didn't quite see that he was looking to replace a literal /, good eye! – dougBTV Jun 4 '13 at 12:41
  • No one for Geany? – SPS Jun 10 '13 at 19:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.