Global Find and Replace

Although the tone of some of the contributors to this thread is both unfortunate and, IMHO, to be deplored there is some good come out of it, this little hint from Korm is one example. may I make a suggestion that one of the more knowledgeable members write a sticky on searching within the application, if, that is, they have the time and inclination to do so? I would but I absolutely do not have the knowledge but would very much value such a sticky.

Finally may I say that I believe that the vast majority of members are very grateful to those expert contributors who unfailingly give good, solid advice and I thank them for their patience. :smiley:

What would you like in a sticky forum topic about searching that’s not covered in search-related Tips and Tutorials?

Excellent! Thanks for reminding me.

While I understand the dangers of such a feature, I too would love to be able to do a global find a replace across a database.

I have a database with 3,000+ notes I imported from a program called Scholar’s Aid. In the process of exporting those notes into rtfs, all of the Spanish language diacritics were switched in a systematic way. Ă© became È, Ă­ became Ì, and so on. Since I don’t otherwise use the characters È, Ì, Ò, Û, and others, it would seem useful to just do a global find a replace for each of them instead of going file by file as I currently do.

1 Like

[Cross-posting this here as well.]

From what I can tell, no changes have been made within the app to support multi-file search-and-replace, so I figured I’d share the solution I ended up using in case it helps someone else down the line.

While @korm’s script is much appreciated, the warnings gave me pause, so I sought something a little more robust and familiar. Enter VS Code.

:warning: I haven’t spent enough time with this to be 100% sure that I didn’t bork something. So far so good, though. :nerd_face:

Use Case

I have a few thousand markdown files exported from Ulysses representing about 5 years of world-building notes for a future fiction book series. About two years in, I changed the name of a major character, but didn’t bother to go back and fix it because, well, Ulysses also doesn’t have a global search-and-replace. :pensive:

I’d already imported all the files into DT by way of discovering whether it’s got what I need to help me rediscover my own thoughts (answer: probably!). I’d also completed a major tagging exercise designed to help me track the source of each note as I begin to slice and dice and rearrange them. Only mentioning this because, if I’d known that global search-and-replace wasn’t going to be available in-app, I’d probably have reversed the order, fixing updating the character’s name in the original markdown files before importing into DT.

The Solution

  1. Prep

    • File > Export > Database Archive
 #safetyfirst!
    • Smart Group to collect all files containing the old character name
  2. Update document titles

    • Select all files in the Smart Group
    • Scripts menu > Rename > Replace Text


    This allowed me to change ever occurrence of “Adrian” to “Adrim” in the file list.

  3. Update file contents

    • Right-click on the database and select Show in Finder
    • Right-click on the revealed .dtBase2 file > Open With > Other

    • Select Visual Studio Code
    • Perform a global replacement in VS Code, being careful to use whole-word search and carefully inspecting the search results before performing the bulk replacement. Caveat lector: this is where it’s possible to do some real damage if you don’t know what you’re doing!

    Once VS Code had saved all the file changes, they appeared instantly in DEVONThink! #problemsolved

Needless to say, this should work with any other text editor, be it a command-line tool, Atom/Sublime, BBEdit
whatever. It’s rather wonderful that DT’s “database” is just a file bundle rather than in some inscrutable binary, thus enabling this kind of back-door power fix.

Thanks again, DT Team!