split files

English support forum

Moderators: Hacker, petermad, Stefan2, white

Post Reply
User avatar
chrizoo
Senior Member
Senior Member
Posts: 351
Joined: 2008-03-12, 02:42 UTC

split files

Post by *chrizoo »

.
Hi. Can TC split files ... not splitting by size but by search term ?

e.g.
I have a multi vcf file (virtual business card), that I want to split into separate files upon each occurence of the string "BEGIN:VCARD".

Can this be done in TC?
If not, can you suggest a good alternative?

many thanks

Code: Select all

BEGIN:VCARD
...
...
...
END:VCARD

BEGIN:VCARD
...
...
...
END:VCARD

BEGIN:VCARD
...
...
...
END:VCARD
Last edited by chrizoo on 2011-12-11, 22:32 UTC, edited 2 times in total.
User avatar
MVV
Power Member
Power Member
Posts: 8713
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV »

You need not just regular truncate but trancate by condition (floating truncate offset) so you need some tool that is able to do it. BTW, you need to split a file and not truncate it (truncation is just deletion of all file contents after some offset).

Have you tried to find some tool that is designed to work with for your VCF files?
User avatar
chrizoo
Senior Member
Senior Member
Posts: 351
Joined: 2008-03-12, 02:42 UTC

Post by *chrizoo »

you are right, I changed title and OP accordingly (truncate -> split)
Have you tried to find some tool that is designed to work with for your VCF files?
I ran into this issue a couple of times with various files, so I am looking for a general solution, not something specific for a single file type.
User avatar
MVV
Power Member
Power Member
Posts: 8713
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV »

For text files you may use following batch:

Code: Select all

@echo off
if -%1==- echo Specify filename and target folder as parameters! E.g. %%P%%N %%T for TC. & pause & goto :EOF
set cnumber=0
set output=nul
set output_prefix=%~n1
if not -%2==- set output_prefix=%2\%output_prefix%

for /f "usebackq delims=" %%l in (`type %1`) do call :go "%%l"
pause
goto :EOF

:fmt_output
set /a cnumber=%cnumber%+1
set output_postfix=000%cnumber%
set output_postfix=%output_postfix:~-4%
set output="%output_prefix%_%output_postfix%.vcf"
goto :EOF

:go
echo %~1|find "BEGIN:VCARD">nul
if not errorlevel 1 goto go_found
echo %~1>>%output%
goto :EOF

:go_found
call :fmt_output
echo Creating %output%...
echo %~1>%output%
goto :EOF
It will create files mm_0001.vcf, mm_0002.vcf etc for source file mm.vcf in current folder (or in folder that is specified in 2nd parameter if specified). Note that it will overwrite them w/o questions. May work bad if quotes or characters <, >, | are in a file (have no test files).
User avatar
Gral
Power Member
Power Member
Posts: 1609
Joined: 2005-01-26, 15:12 UTC

Post by *Gral »

Try GSplit
User avatar
chrizoo
Senior Member
Senior Member
Posts: 351
Joined: 2008-03-12, 02:42 UTC

Post by *chrizoo »

.
you guys are wonderful, thanks!
I'll look into that
Post Reply