On 11/19/12 20:52, ping wrote:
> On 11/17/2012 1:50 PM, Tim Chase wrote:
>> On 11/16/12 18:36, Ant wrote:
>>> this one is something I need help in. Say I have thousands
>>> of files and I wanted to concatenate them all into one. THis
>>> is easy to do, I can just do it outside Vim using bash script
>>> "cat * > allfiles.txt" or something.
>>>
>>> But how would you concatenate heaps of files together,
>>> separating them by its filename or some unique thing
>>
>> to do similarly in Vim
[snip my vim solution]
> try this: http://code.google.com/p/filemerger/
If I were using other tools, I'd likely just reach for standard Unix
tools:
find /path/to/source -type f -exec sed '1s!.*!---------\n{}\n&!'
{} \; > /path/to/dest/out.txt
where "!" is a separator that shouldn't be found in a filename.
Other popular choices might be "@" or "#" or "+". This also has a
downside of launching a sed process for every file to be processed.
That should handle any number of args/files pretty nicely, as well
as recurse into directories. If you know the number of files will
be pretty reasonable[1] and they're all in the same directory's
filespec, you can do it with one awk command:
awk '{if (FILENAME != prev_filename) {print "========="; print
FILENAME; prev_filename = FILENAME;}; print $0;}'
/path/to/source/*.txt > /path/to/dest/out.txt
On Windows, I might do something like
C:\TEMP\> find /v "SOMESTRINGTHATDOESNTEXISTANYWHERE" source\*.txt
> dest\out.txt
which has a slightly different output format, but should still get
everything as long as you choose some unique string you know won't
exist anywhere in your source files.
-tim
[1]
the output of "getconf ARG_MAX" on Linux tells you the maximum size
of a command. On my Debian box, it's about 2megs. That's a lot of
file-names, but I've hit that limit occasionally.
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php