PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > V-Card split script
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

V-Card split script

Réponse
 
LinkBack Outils de la discussion
Vieux 13/03/2008, 20h09   #1
ChrisOD
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut V-Card split script

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


  Réponse avec citation
Vieux 13/03/2008, 20h41   #2
John W. Krahn
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: V-Card split script

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
  Réponse avec citation
Vieux 13/03/2008, 20h44   #3
andyhaupt@netscape.net
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: V-Card split script

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
  Réponse avec citation
Vieux 13/03/2008, 21h13   #4
ChrisOD
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: V-Card split script

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
  Réponse avec citation
Vieux 13/03/2008, 21h30   #5
pk
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: V-Card split script

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.

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 02h56.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,12294 seconds with 13 queries