merging text files & select specific lines

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, MudGuard

Post Reply
utreg-4ever
Posts: 1
Joined: Fri Oct 05, 2007 8:45 am

merging text files & select specific lines

Post by utreg-4ever »

Hi there!
Hopefully someone around here is so kind to help me out.

How can i merge the contents of several textfiles into one easily?
Then i need to filter the file: i only need the lines with a certain word in it.

Preferably i need a macrocode for this, but if there is a 2 or 3 click manual procedure for it, that would be very welcome too!

Thanks in advance!
User avatar
Bob Hansen
Posts: 1516
Joined: Sun Mar 02, 2003 8:15 pm
Location: Salem, NH
Contact:

Post by Bob Hansen »

Here are the steps to take.

You can open the first file, then do Edit/Insert/Filename or Files......
(Maybe do SaveAs a new file name).

Then you can Bookmark lines that meet a Find spec for the "word".
Then Search/Invert All Bookmarks
Then Edit/Delete/Bookmarked lines.
(Maybe do SaveAs a new file name).

That will leave you with only those lines that have the "word" you did a Search for.
Hope this was helpful.............good luck,
Bob
Bah
Posts: 2
Joined: Wed May 14, 2008 8:40 am

Post by Bah »

Is there a limit on the number of files you can do this to? I have about 700 files I need to merge into one but it will not do them all at once using this method. It allows me to select them but then does nothing when I hit Open.
ACRobin
Posts: 134
Joined: Fri Nov 04, 2005 9:51 pm
Location: Northumberland,UK
Contact:

Post by ACRobin »

As Bob has answered re: merging files (open blank document - Edit -> Insert -> Files) this will merge many files - I assume the limit will be the space taken i.e. "what is the largest files you can have in TP", this is in the help and answered in the forum somewhere previous.
Bah
Posts: 2
Joined: Wed May 14, 2008 8:40 am

Post by Bah »

I did find the answer, after searching further. Copy /b *.<file extension> merged.txt

I bonked myself on the head when I saw it thinking, “Why didn’t I think of this�.

Thanks for the response.
User avatar
Cloink
Posts: 81
Joined: Thu Sep 09, 2004 1:44 pm

Post by Cloink »

Bob's suggestion will of course work, I've never even noticed the 'Insert Files' before (!) - and wouldn't have thought of Find/BookmarkAll/Invert - my suggestion is somewhat different, so take your pick...

Ctrl-F5 / Find in files

The results go to the 'Search Results' window - with the advantage that you can double-click a line to go straight to that line in that file. If you need to save the output separately, you must CopyAll in the Search Results window, then paste into another document, then edit out the prefix on each line that TP has added - you can do this in one go with an appropriate regex/null to find/replace.

If the set of files covers multiple directories not all with the same root, you can direct the 'Find in Files' dialogue to use a list of files in another text file by entering @[path]/filelist.txt in the 'In Files' input box.

[This latter method has a minor bug in that it iterates over all sub-folders and repeats the results as many times as there are sub- (and sub-sub-) folders. Specify an empty 'In Folder' directory to prevent this: your filelist.txt file includes the path for each file.]
Post Reply