DonationCoder.com forum
 
Read-only archive. This is a static copy of the DonationCoder.com forum. Reading and searching work as before; logging in, posting and private messages do not.
Archive of 2026-10-21 · About this archive · Main site

Author Topic: SOLVED: Recursive Search and Replace in Nested Folders  (Read 20,441 times)

nkormanik

  • Participant
  • Joined in 2010
  • *
  • Posts: 563
SOLVED: Recursive Search and Replace in Nested Folders
« on: December 18, 2012, 08:19 PM »

Surely such utility programs exist, so I am mostly asking for your suggestions.

In a set of folders are text files.  I need to search for UNDERLINE characters, and change each to TAB characters.

Ideally I'd like the operation to be recursive, so that I can use the top containing folder, and all folders within will be drilled into, finding the text files, and changing the UNDERLINE to TAB.

Additionally, the program must allow me to put in TAB.  Maybe ASCII 9?  Could be an issue.

Thanks much.

Nicholas Kormanik


Ath

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 3,649
    • Participated in NANY Challenge Eleven Times
    • Coding Snacks
    • Linux User
    • Hardware Hacker
Re: SOLVED: Recursive Search and Replace in Nested Folders
« Reply #1 on: December 18, 2012, 08:45 PM »
A lot of descent editors, like Notepad++, PsPad and others, support find/replace functions on external files, including subdirectories. Usually you can (optionally) specify regex-like or c-style characters like \t for a <tab>, etc.
/Ton
Ath's software collection, Quote: "A problem well stated is a problem half-solved." (Charles Kettering)

rjbull

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 3,217
Re: SOLVED: Recursive Search and Replace in Nested Folders
« Reply #2 on: December 18, 2012, 10:32 PM »

NigelH

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 210
Re: SOLVED: Recursive Search and Replace in Nested Folders
« Reply #3 on: December 18, 2012, 11:14 PM »
Swiss File Knife as well
http://stahlworks.com/dev/swiss-file-knife.html

replace function
http://stahlworks.com/dev/index.php?tool=rep

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,736
    • Coding Snacks
Re: SOLVED: Recursive Search and Replace in Nested Folders
« Reply #4 on: December 18, 2012, 11:14 PM »
I havn't tried this one but the features seem a match. Requires .NET 4 though. Might be alright if you are running W7 or later.  There may be a run-time download if you need the .NET 4.

nkormanik

  • Participant
  • Joined in 2010
  • *
  • Posts: 563
Re: SOLVED: Recursive Search and Replace in Nested Folders
« Reply #5 on: December 19, 2012, 12:17 AM »
Goodness, quite the assortment to choose from.  Thanks for all your help!

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,736
    • Coding Snacks
Re: SOLVED: Recursive Search and Replace in Nested Folders
« Reply #6 on: December 19, 2012, 12:22 AM »
Goodness, quite the assortment to choose from.  Thanks for all your help!

Out of curiosity what flavor of Windows are you running?

nkormanik

  • Participant
  • Joined in 2010
  • *
  • Posts: 563
Re: SOLVED: Recursive Search and Replace in Nested Folders
« Reply #7 on: December 19, 2012, 12:28 AM »
Still with good ol' XP Pro.

I guess at some point I'll have to move to Windows 8, huh.

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,736
    • Coding Snacks
Re: SOLVED: Recursive Search and Replace in Nested Folders
« Reply #8 on: December 19, 2012, 01:07 AM »
I wouldn't if I were you. :)
To be honest I haven't tried it. But from what I hear it's fine for devices but not great for desktops. If you have a desktop PC I'd go with W7.

There's nothing wrong with XP if it drives the devices you have. What kills OS first is usually device support.  Then eventually they are just obsolete for capacity. Things outgrow it. I loaded Win98 in a virtual machine about 6 months back just for grins. I was shocked to remember the entire supported file system was smaller than some of my downloads.  :)

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,736
    • Coding Snacks
Re: SOLVED: Recursive Search and Replace in Nested Folders
« Reply #9 on: December 19, 2012, 01:10 AM »
I just looked on the .NET 4 redist. download page. Apparently you can use it on XP if you have SP3 installed.

nkormanik

  • Participant
  • Joined in 2010
  • *
  • Posts: 563
Re: SOLVED: Recursive Search and Replace in Nested Folders
« Reply #10 on: December 19, 2012, 01:36 AM »
Installed without any problem.  Thanks.

As anticipated, in the programs tried so far, can't figure out how to put in a TAB character.  They seem to be geared for regular text.

x16wda

  • what am I doing in this handbasket?
  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 888
    • Participated in NANY Challenge Once
Re: SOLVED: Recursive Search and Replace in Nested Folders
« Reply #11 on: December 19, 2012, 02:20 AM »
If you can stand a command line, the C-style option below might work.  I've used this one and gsar.exe both in various batch processes, can't recall offhand now why I needed both of them... maybe one of them didn't want to replace in place?  hmm... <walking off muttering to himself...>


Code: (text)
Find And Replace Text  v1.99b                         by Lionello Lunesu

Usage: FART [options] [--] <wildcard>[,...] [find_string] [replace_string]

Options:
 -h, --help          Show this help message (ignores other options)
 -q, --quiet         Suppress output to stdio / stderr
 -V, --verbose       Show more information
 -r, --recursive     Process sub-folders recursively
 -c, --count         Only show filenames, match counts and totals
 -i, --ignore-case   Case insensitive text comparison
 -v, --invert        Print lines NOT containing the find string
 -n, --line-number   Print line number before each line (1-based)
 -w, --word          Match whole word (uses C syntax, like grep)
 -f, --filename      Find (and replace) filename instead of contents
 -B, --binary        Also search (and replace) in binary files (CAUTION)
 -C, --c-style       Allow C-style extended characters (\xFF\0\t\n\r\\ etc.)
     --cvs           Skip cvs dirs; execute "cvs edit" before changing files
     --svn           Skip svn dirs
     --remove        Remove all occurences of the find_string
 -a, --adapt         Adapt the case of replace_string to found string
 -b, --backup        Make a backup of each changed file
 -p, --preview       Do not change the files but print the changes
vi vi vi - editor of the beast

nkormanik

  • Participant
  • Joined in 2010
  • *
  • Posts: 563
Re: SOLVED: Recursive Search and Replace in Nested Folders
« Reply #12 on: December 19, 2012, 02:52 AM »
Nice job copying all those options.  Command line is fine.  Whatever gets the mission accomplished.  Thanks a lot.

Two programs so far do allow for TAB.  So, all this help has been well worth it.

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,736
    • Coding Snacks
Re: SOLVED: Recursive Search and Replace in Nested Folders
« Reply #13 on: December 19, 2012, 03:06 AM »
Esp. with raw substitution this kind of filtering is ideal for sed stream editor. Only hassle is it's a Linux command.  But you may find binary Windows ports.  All you need is something that searches every file for the target character, such as grep and when you find a hit, you pipe it into sed.

In fact the Windows port of the find command will do it. Depends how much of this type of thing you need to do. If these types of tasks pop up all the time it may be worth setting up a Linux shell like bash that natively handles Linux command line binaries ported to Windows.

There are dozens of sed "one liners" you can find on the web that can do quite a bit when it comes to substitutions.
For a one-shot it's not worth it though. :)

skwire

  • I eat Coding Snacks for breakfast...
  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,297
    • Participated in NANY Challenge Seventeen Times
    • Coding Snacks
    • Superboy Coder
    • Cody Award
    • Volunteers/Staff
    • Gathering Badge
Re: SOLVED: Recursive Search and Replace in Nested Folders
« Reply #14 on: December 19, 2012, 10:26 AM »
@Nick: Please let me know if/when you have a working solution and I'll mark this thread as solved and move it.  Thanks!  ;)

nkormanik

  • Participant
  • Joined in 2010
  • *
  • Posts: 563
Re: SOLVED: Recursive Search and Replace in Nested Folders
« Reply #15 on: December 19, 2012, 10:34 AM »
The program I liked best was...

http://www.nodesoft.com/searchandreplace

Did a super job.

Thanks for that suggestion!

So, Skwire, unless anyone has something else to add, this thread is done.

rjbull

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 3,217
Re: SOLVED: Recursive Search and Replace in Nested Folders
« Reply #16 on: December 19, 2012, 03:34 PM »
Esp. with raw substitution this kind of filtering is ideal for sed stream editor. Only hassle is it's a Linux command.  But you may find binary Windows ports.
Here are two:

Original address: https://www.donationcoder.com/forum/index.php?topic=33335.0