Ubuntu – Find and replace text in multiple files using Geany

geanysearchtext-editor

I'm looking for a method to find and replace text in hundreds of files.

I know that Geany can find text in multiple files. That's good.
But how do I replace the text?

Geany seems to do it only in the file that's currently opened. How do you open all files in Geany where it finds the search string?

Best Answer

You can do this by waiting for a plugin to appear in this sense, or by using the terminal. I think the second way is better for the moment. I will explain how.

To open all files, in which a specific string is found, from inside of a directory (and subdirectories) open Geany, select Terminal tab from Message Window and run next command inside:

grep -rHIF --exclude='/directory_path/*~' -- 'text_to_find' /bin/bash /directory_path/* | geany `awk 'BEGIN {FS="[:]"} {print $1}'`

For example, to open all bash scripts that I have in my /home/radu/bin directory with Geany, I run next command:

grep -rHIF --exclude='/home/radu/bin/*~' -- '#!/bin/bash' /home/radu/bin/* | geany `awk 'BEGIN {FS="[:]"} {print $1}'`

Geany

To open these files in a new instance of Geany without to load the previous session's files, use -is arguments for geany command:

grep -rHIF --exclude='/directory_path/*~' -- 'text_to_find' /bin/bash /directory_path/* | geany -is `awk 'BEGIN {FS="[:]"} {print $1}'`

Now that you have all the files that you need opened in a single session of Geany, press Ctrl+H to open the Replace dialog, insert the text to find, insert the text to replace and press In Session button:

Geany Search & Replace Dialog