Easy way to search & replace many word pairs in multiple files (Win & Linux) - text-editor

I have a map of values:
oldWord1 newWord1
oldWord1 newWord1
...
oldWordn newWordn
In many files.
What is the easy way to replace them efficiently without manually doing search & replace for each pair?
I am looking for some simple tools or some hints how to do it using Eclipse, Vim , Notepad++ etc with the help of some scripting.

SynWrite editor (Windows) can do scripting in Python. Write a py-plugin for this task, assign it a hotkey, and then call this plugin with hotkey.

Related

Multi cursor editing in multiple (open) documents

I have 10-20 configuration files in which I have to change the same setting quite often.
I was thinking about multi cursor approach (like in Sublime Text), but in multiple documents at the same time.
I can use find/replace in files, etc, but I would love to see what is being edited and selecting same 'setting key' just by pressing CMD + D would be just amazing.
Anyone knows an editor which can do multi-cursor editing in multiple buffers/documents? Or maybe another way of efficiently editing multiple files which are almost identical?
This is not possible in Sublime, nor any other editor of which I'm aware. In Sublime, for example, you can have multiple open files in different tabs and/or windows, but only one has the focus at any one time. It just doesn't make much sense to have input going to multiple windows at once.
Your problem is just crying out for a scripted solution. In Sublime you can create macros and Python-based plugins, as well as using regex-based search and replace. If you're using a shell like bash with access to the standard array of command-line utilities, you can use any number of ways (sed, awk, Python, Perl, expect, and many more) to identify the desired files, select the setting that needs to be changed, and change it, either automatically or with confirmation at each step.

AppleScript Replace File

I'd like to write an AppleScript for replacing three system files with ones I've modified. I'd like to do this with an AppleScript instead of manually replacing them because I'll have to replace three files every time there's an OS X update. Specifically, I'll be replacing stock graphics drivers with ones I've modified to support a graphics card which is connected via Thunderbolt. Is it possible to write an AppleScript for replacing one file with another? I ask because I know that when you replace a file, a dialog pops up with three options, and I don't know how to address that.
You can do this with Finder:
set freshFile to choose file
tell application "Finder"
move freshFile to desktop replacing yes
end tell
All you need to do is work out the source and destination paths to completely automate the script.
Many scripters do not like working with Finder, for a variety of reasons. If you want something that is incredibly fast, you would use the do shell script inside of your AppleScript:
do shell script " mv -f ~/Desktop/ArlandaTilUppsala.pdf ~/Documents/Employ.pdf"

Searching just for filenames

I want to search for only filenames in "Windows Search API" by visual c++ .
and i don't want to search for contents because its time consuming.
does "windows search API" have this option ?
As described (although not that well) in the Advanced Query Syntax reference, you can use:
filename:foo
to search for filenames containing "foo".
The easiest way ist to use the "Name:myfiletosearchfor" Syntax with ISearchQueryHelper.
Here is a sample application. It is MFC but the specific parts are easy to convert.
http://www.arlt.eu/blog/wp-content/uploads/2008/08/wssample.zip

Replace in multiple files - graphical tool for Linux

It needs to be graphical. No sed, awk, grep, perl, whatever. I know how to use those and I do use them now, but I need to cherry-pick each replace in 300+ files.
I want a tool where I can:
type a search string
type a replace string
select a directory and file extension
and it would recursively go into each file in that directory and its sub-directories, open it and scroll to the place where search string is and offer two options:
replace (and find next)
find next
Nothing more. Reg.exp. support is a plus, but not required.
SOLVED: Regexxer is exactly what I needed. In case someone needs it on Slackware, here's what you need to download and how to compile it (choosing correct version of each dependency can be a PITA)
I think regexxer is exactly what you're looking for:
Regexxer
regexxer is a nifty GUI search/replace tool featuring Perl-style regular
expressions. If you need project-wide substitution and you’re tired of
hacking sed command lines together, then you should definitely give it a try.
See also the screenshot, looks a lot like what you're describing:
Emacs + dired + query-replace-regexp
For complete recipe follow this link (it's rather long, covering all possible alternatives),
jEdit does exactly what you need. It is written in Java and works well in Linux, Windows and OS X (probably other operating systems also).
Lately Kate (if you use KDE) can do it, but in a very tricky way. Go to "Edit>Search in Files", and choose the folder within which your files exist.
The trick is that only after the search results appear, you will find a text box and a button called "Replace checked". This button will do what you want.
I use gVim for this task all the time. I open up all the files at once, then use the commands to perform a subsitution on each file, asking for confirmation. Generally I use < 20 files, so I open them as tabs and use this:
:tabdo %s/foo/bar/gc
gVim works fine on Windows :) My coworkers often use Textpad to do this same thing, but I'd say gVim is much more efficient at it.
If you are a KDE user there's also kfilereplace.

Text indexer search tool which can filter by punctuation?

This is not a programming question per se but a question about searching source code files, which help me in programming.
I use a search tool, X1, which quickly tells me which source code files contain some keywords I am looking for. However it doesn't work well for keywords which have punctuation attached to them. For example, if I search for "show()", X1 shows everything that has "show" in it including the too many results from "MessageBox.Show(.....)" which I don't want to see.
Another example: I need to filter to show ".parent" (notice the dot) and not show everything that has "parent" (no dot) in it.
Anyone knows a text search tool which can filter by keywords that have punctuation? I really prefer a desktop app instead of web based tool like Google (I find it clunky).
I am looking for a tool which indexes words and not a general file searcher like Windows File Explorer.
If you want to search code files efficiently for keywords and punctuation,
consider the SD Source Code Search Engine. It indexes each source langauge according
to langage-specific rules, so it knows exactly the identifiers, keywords,
strings, comments, operators in that langauge and indexes it according to
those elements. It will handle a wide variety of languages: C, C++, Java, VB6, C#, COBOL,
all at once.
Your first query would be posed as:
I=show - I=MessageBox ... '('
(locate identifiers named "show" but eliminate those that are overlapped by
MessageBox leftparen).
You second query would be posed as simply
'.' I=parent
See http://www.semanticdesigns.com/Products/SearchEngine/index.html
It seem to be the job of tools like ctags and cscope.
Ctags is used to index declarations of source files (many languages supported) and Cscope for in-depth c file analysis.
These tools are more suited for a per project use in my opinion. Moreover, you may need to use another tool to use these index, I use vim myself for this purpose, but many text editors use ctags.
The tool from DTSearch.com.

Resources