Page 1 of 1
merging text files & select specific lines
Posted: Fri Oct 05, 2007 8:55 am
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!
Posted: Fri Oct 05, 2007 3:18 pm
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.
Posted: Wed May 14, 2008 8:42 am
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.
Posted: Wed May 14, 2008 10:32 am
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.
Posted: Wed May 14, 2008 11:16 am
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.
Posted: Thu May 15, 2008 9:05 am
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.]