Page 1 of 1

Split Multiple vCard vcf file into many

Posted: 14 Jun 2022 22:48
by drgt
Hi
Each record starts "BEGIN:VCARD" with and ends with "END:VCARD"
Output can start with 1.vcf to as many as they are.

Thanks

Re: Split Multiple vCard vcf file into many

Posted: 15 Jun 2022 10:27
by Aacini
Start the Batch file with

Code: Select all

@echo off
and then put the rest of commands...

At the very beginning of this site there is this thread, so there is no way that you had not see it...

Antonio

Re: Split Multiple vCard vcf file into many

Posted: 15 Jun 2022 21:16
by drgt
Thank you Antonio, I visited the thread you mentioned.
Blame it on old age (70), blame it on stupidity, I do not get it!
Please set forth exactly what you are asking me to supply.

Note:
As an alternative to numbered files output, please show the code for "LastName(.FirstName.MiddleName)*.vcf" output.
*Omit parenthesis if record is missing this data.

Re: Split Multiple vCard vcf file into many

Posted: 17 Jun 2022 13:02
by drgt
AnyOne?

Re: Split Multiple vCard vcf file into many

Posted: 17 Jun 2022 15:26
by Aacini
Ok. To clarify what the first thread is asking for, I suggest you to carefully read this post. After that, answer these questions:
  • How many input files do you want to process? One? Many?
  • Please, post here a small example of an input file enclosed between [code] and [/code] tags. Of course, we could guess the format of the input files. However, in order to test the code we could write, we need to also write an input data example file! Do you want that we also write such a data file? :x
  • Post the desired output files than should result after processing the listed input example file.
  • Do you want to generate output files with names as 1,2,...9,10,11,...? Mean this that the order of the output files don't matters? Or do you want names with (for example) 3 digits like 001, 002,...009,010,011...
  • Do you want to preserve of remove the processed input files? If preserved, they will mix with the generated output files, but the program could delete each processed file... Unless the output files be placed in a different directory than the input file...
  • Should I continue with this? :(
Now, read again the post given above; perhaps you could comprehend it in a different way.

Antonio

PS: I may have spent more time writing this long answer than it would have taken to write the desired batch file... This means that largely incomplete questions like this one are frowned upon here

Re: Split Multiple vCard vcf file into many

Posted: 21 Jun 2022 20:22
by Aacini
This code do what the OP requested, more or less...

Code: Select all

@echo off
setlocal EnableDelayedExpansion

set "num=1"
for /F "delims=" %%a in (%1) do (
   >> !num!.vcf echo %%a
   if "%%a" equ "END:VCARD" set /A num+=1
)
test.vcf input file:

Code: Select all

BEGIN:VCARD
TYP:SMS;IN
BOX:INBOX
READ:0
DATE:20211102T113146U
NUMBER:6012589631
BODY;CHARSET=1253
END:VCARD
BEGIN:VCARD
TYP:SMS;IN
BOX:INBOX
READ:0
DATE:20211102T104259U
NUMBER:6256945389
BODY;CHARSET=1253:TEST
END:VCARD
BEGIN:VCARD
TYP:SMS;IN
BOX:INBOX
READ:0
DATE:20220118T090000U
NUMBER:1234567890
BODY;CHARSET=1253:TEST
END:VCARD
Put the name of input file in the parameter. For example:

Code: Select all

C:\Users\Antonio\Documents\Test> test test.vcf

C:\Users\Antonio\Documents\Test> type 1.vcf
BEGIN:VCARD
TYP:SMS;IN
BOX:INBOX
READ:0
DATE:20211102T113146U
NUMBER:6012589631
BODY;CHARSET=1253
END:VCARD

C:\Users\Antonio\Documents\Test> type 2.vcf
BEGIN:VCARD
TYP:SMS;IN
BOX:INBOX
READ:0
DATE:20211102T104259U
NUMBER:6256945389
BODY;CHARSET=1253:TEST
END:VCARD

C:\Users\Antonio\Documents\Test> type 3.vcf
BEGIN:VCARD
TYP:SMS;IN
BOX:INBOX
READ:0
DATE:20220118T090000U
NUMBER:1234567890
BODY;CHARSET=1253:TEST
END:VCARD
Antonio

Re: Split Multiple vCard vcf file into many

Posted: 23 Jun 2022 02:15
by drgt
Thank you Aacini.
To the point as always!

As an alternative to numbered files output, would it be too hard to code for "LastName.FirstName.MiddleName.vcf" output?
That info is stored in the line always starting with "N:"

Sample input file:
BEGIN:VCARD
VERSION:3.0
N:Last;First;Middle;Prefix(Mr.);Suffix(Sr.)
FN:First Last
TEL;TYPE=CELL:123-456-7777
TEL;TYPE=HOME:222-333-4444
END:VCARD
BEGIN:VCARD
VERSION:3.0
N:Smoe;Joe;Jim;Dr.;
FN:Joe Smoe
TEL;TYPE=HOME:222-222-2222
TEL;TYPE=CELL:999-999-9999
END:VCARD