|
|
|
|
||||||
| comp.unix.shell Using and programming the Unix shell. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
I have a 13Mb vcf file and would love to split this into it's
component parts. i.e. I want to have a seperate .vcf file for each addressee. For those script experts that are unfamiliar with v-cards it is a text file that looks like this. BEGIN:VCARD VERSION:3.0 N:LastName;FirstName;;; FN:FirstName LastName .... .... END:VCARD BEGIN:VCARD .... I'd like to have the seperate .vcf files named on the N field with a syntax like: LastName-FirstName.vcf Hope someone can give some hints to a script newbie. Chris |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
ChrisOD wrote:
> I have a 13Mb vcf file and would love to split this into it's > component parts. > > i.e. I want to have a seperate .vcf file for each addressee. > > For those script experts that are unfamiliar with v-cards > it is a text file that looks like this. > > BEGIN:VCARD > VERSION:3.0 > N:LastName;FirstName;;; > FN:FirstName LastName > ... > ... > END:VCARD > BEGIN:VCARD > ... > > I'd like to have the seperate .vcf files named on the N field > with a syntax like: LastName-FirstName.vcf perl -pe' BEGIN { $/ = "END:VCARD\n" } open STDOUT, sprintf ">>%s-%s.vcf", /^N [^;]+);([^;]+);/m' YourBigFile.vcf John -- Perl isn't a toolbox, but a small machine shop where you can special-order certain sorts of tools at low cost and in short order. -- Larry Wall |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
Try awk.
vcf.awk: /END:/ { # end of vcard vcard = vcard $0; print vcard >filename; vcard = ""; next; } { # append line to vcard vcard = vcard $0 "\n"; } /^N:/ { # N:LastName;FirstName;;; n = split($0,a,":"); n = split(a[2],b,";"); filename = b[1] "-" b[2] ".vcf"; } and then awk -f vcf.awk vcffile On 13 Mrz., 21:09, ChrisOD <ch...@dont.send.me.any.email> wrote: > I have a 13Mb vcf file and would love to split this into it's > component parts. > > i.e. I want to have a seperate .vcf file for each addressee. > > For those script experts that are unfamiliar with v-cards > it is a text file that looks like this. > > BEGIN:VCARD > VERSION:3.0 > N:LastName;FirstName;;; > FN:FirstName LastName > ... > ... > END:VCARD > BEGIN:VCARD > ... > > I'd like to have the seperate .vcf files named on the N field > with a syntax like: LastName-FirstName.vcf > > Hope someone can give some hints to a script newbie. > > Chris rgds andreas |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
On 2008-03-13, ChrisOD <chris@dont.send.me.any.email> wrote:
> I have a 13Mb vcf file and would love to split this into it's > component parts. > > i.e. I want to have a seperate .vcf file for each addressee. > > For those script experts that are unfamiliar with v-cards > it is a text file that looks like this. > > BEGIN:VCARD > VERSION:3.0 > N:LastName;FirstName;;; > FN:FirstName LastName > ... > ... > END:VCARD > BEGIN:VCARD > ... > > I'd like to have the seperate .vcf files named on the N field > with a syntax like: LastName-FirstName.vcf > > Hope someone can give some hints to a script newbie. > > Chris > > Thanks John and Andy. The awk example worked just fine. The perl only extracted the first vcard so ![]() I love the ease of here for someone who is too rusty at scripts. You guys rock. Chris |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
ChrisOD wrote:
> I have a 13Mb vcf file and would love to split this into it's > component parts. >[cut] > I'd like to have the seperate .vcf files named on the N field > with a syntax like: LastName-FirstName.vcf > > Hope someone can give some hints to a script newbie. Besides awk, another way is to use csplit (assuming max 100000 vcards): $ csplit -n 5 -z vcard.txt '/BEGIN:VCARD/' '{*}' This is not really useful by itself since you don't have much control over file names. However, you can use a subsequent loop to rename all the files. -- All the commands are tested with bash and GNU tools, so they may use nonstandard features. I try to specify when something is nonstandard (if I know that), but I may still miss something. Corrections are welcome. |
|
![]() |
| Outils de la discussion | |
|
|