4

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?

4
  • Do you have to use Geany (I've never heard of it), or are you open to find/replace other possibly easier ways?
    – RGS
    Jun 1, 2013 at 17:54
  • Take a look at my answer here, and see if it will work for you.
    – Mitch
    Jun 1, 2013 at 19:07
  • I use Geany because it is very useful for C/C++. I has a lot of plug-ins, I hope a plug-in that does what I want, exists. I look for it. I've just tried Kate, but it seems less powerful than Geany. Using Kate, how can I search in multiple files and replace text in them? Thanks
    – SPS
    Jun 2, 2013 at 13:20
  • "Find and Replace feature for Entire Project... (meaning file and replace in all files inside the project directory... more advanced search and replace [open documents, in folder, find all in folder, etc...] like DreamWeaver), Go to absolute character position in a given file (like pspad). bump " is here: geany.org/Support/PluginWishlist I don't know if plug is already available
    – SPS
    Jun 2, 2013 at 14:33

2 Answers 2

2

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

2
  1. Select all the files that you want to edit, and open them with Geany.
  2. From the Geany menu select Search -> Replace.
  3. A new Replace window will open up. Under the Replace All section select In Session as shown in the picture below. In this example I have chosen to globally replace the string "search-text" by the string "replace-text".
  4. From the Geany menu select File -> Save All.
  5. From the Geany menu select File -> Close All and close Geany, or select File -> Quit.

enter image description here

This is the way to replace text in multiple files in Geany. If you want to find all the instances of text in multiple files before you replace them, you can select Search -> Find from the Geany menu, and the file names and line numbers of the lines in the files containing the search term will appear in a list in the bottom pane of the Geany window. Any open tabs in Geany whose file names are not found in this list in the bottom pane of Geany can be manually closed one at a time, or you can leave all the tabs open since it doesn't make any difference to the result of your replace operation.

2
  • And how do you open all those files from the bottom pane? Jul 1, 2013 at 7:51
  • The bottom pane can only list files that are already opened as tabs in Geany. For example if you want to edit files that are in a Directory called Project, just select all the relevant files from the Project directory, right-click, and then select Open With and then select Geany to open all the files with Geany. In the Geany window you will see that all of these files are now opened as separate tabs in Geany.
    – karel
    Jul 1, 2013 at 8:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .