Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Converting Text Files into vCard Format

I need to convert a tab-delimited database text file into vCard Format to import into Address Book. I found a Unix Command for the Terminal at http://www.macosxhints.com/article.php?story=20030831221023355 but I am not a programmer and don't have a clue how to safely use the terminal.

Could anybody chat with me briefly to explain the following command:
awk -F\t ' {print "BEGIN:VCARD"; print "VERSION:3.0"; print "N:"$1;
print "TEL;type=WORK;type=pref:"$2; print "END:VCARD" $3; print $3 }'
sourcefile > newfile.vcf

Is F/t a filestring? I figured out that $1, $2, $3 are field numbers. If someone can just show me the format to transform a file name data.txt located (for example) at ~/document/database/data.txt to a file named newfile.vcf, I think I could take it from there.

Thanks!

MacBook Pro Mac OS X (10.4.8)

Posted on Feb 13, 2007 12:28 PM

Reply
Question marked as Best reply

Posted on Feb 13, 2007 1:05 PM

-F \t (note the space between the -F and the \t tells awk to recognize the tab character (shown in this command as "\t" - also note this is a backslash "\" not a forward slash "/") as the input field separator.

sourcefile would be your ~/document/database/data.txt, and the command output is being redirected (that's the >) from screen output to a file named newfile.vcf. If you leave off the > newfile.vcf, the output from the awk command will be printed to your screen, so you can see what would have been written to newfile.vcf had you done the command as originally given.
3 replies
Question marked as Best reply

Feb 13, 2007 1:05 PM in response to Plub

-F \t (note the space between the -F and the \t tells awk to recognize the tab character (shown in this command as "\t" - also note this is a backslash "\" not a forward slash "/") as the input field separator.

sourcefile would be your ~/document/database/data.txt, and the command output is being redirected (that's the >) from screen output to a file named newfile.vcf. If you leave off the > newfile.vcf, the output from the awk command will be printed to your screen, so you can see what would have been written to newfile.vcf had you done the command as originally given.

Feb 13, 2007 6:38 PM in response to j.v.

I'm over my head. I tried to create the command to convert my files. Here is the data from a sample Address Book entry. I pulled it to my desktop and opened it in text edit so I could see the vCard format:

BEGIN:VCARD
VERSION:3.0
N:Bradford;Paul;Lloyd;Dr.;Testcard
FN:Dr. Paul Lloyd Bradford Testcard
NICKNAME:Plub
X-MAIDENNAME:MaidenNameText
ORG:LakeshoreVineyard;Department
TITLE:President
EMAIL;type=INTERNET;type=HOME;type=pref:plbradford@sbcglobal.net
EMAIL;type=INTERNET;type=WORK:paulb@lakeshorevineyard.org
TEL;type=HOME;type=pref:(616) 355-0818
TEL;type=WORK:(616) 394-5500
TEL;type=CELL:(616) 886-5500
item1.TEL:(906) 847-3248
item1.X-ABLabel:_$!<Other>!$_
item2.ADR;type=HOME;type=pref:;;123 W 24th;Detroit;MI;12345;USA
item2.X-ABADR:us
item3.ADR;type=WORK:;;123 Central Ave;Detroit;MI;12345;USA
item3.X-ABADR:us
item4.URL;type=pref:www.homepage.net
item4.X-ABLabel:_$!<HomePage>!$_
BDAY;value=date:1960-01-01
X-AIM;type=HOME;type=pref:plbradford
item5.X-ABDATE;type=pref:1980-10-01
item5.X-ABLabel:_$!<Anniversary>!$_
item6.X-ABRELATEDNAMES;type=pref:Married
item6.X-ABLabel:marital
item7.X-ABRELATEDNAMES:Lynn
item7.X-ABLabel:_$!<Spouse>!$_
item8.X-ABRELATEDNAMES:Paul and Lynn
item8.X-ABLabel:salutation
item9.X-ABRELATEDNAMES:Member
item9.X-ABLabel:member?
item10.X-ABRELATEDNAMES:Active
item10.X-ABLabel:status?
item11.X-ABRELATEDNAMES:M
item11.X-ABLabel:gender
item12.X-ABRELATEDNAMES:47
item12.X-ABLabel:age
X-ABUID:4EF36F2F-3AD6-4A64-81CD-A35300C93A26\:ABPerson
END:VCARD


I then created this command:

awk -F\t ' {print "BEGIN:VCARD"; print "VERSION:3.0"; print "N: "$1 $2 $3 $4 $5; print “NICKNAME: ”$6; print “X-MAIDENNAME: “$7; print “ORG: “$8 $9; print “TITLE: “$10; print “EMAIL;type=INTERNET;type=HOME;type=pref: “$11; print “EMAIL;type=INTERNET;type=WORK: “$12; print “TEL;type=HOME;type=pref: “$13; print “TEL;type=WORK: “$14; print “TEL;type=CELL: “$15; print “item1.TEL: “$16; item1.X-ABLabel: “_$!<Other>!$_ print “item2.ADR;type=HOME;type=pref: “ $17 $18 $19 $20 $21; print “item2.X-ABADR: “us; print “item3.ADR;type=WORK: “;$22 $23 $24 $25 $26; print “item3.X-ABADR: “us; print “item4.URL;type=pref: “$27; print “item4.X-ABLabel: “_$!<HomePage>!$_; print “BDAY;value=date: “$28; print “X-AIM;type=HOME;type=pref: “$29; print “item5.X-ABDATE;type=pref: “$30; print “item5.X-ABLabel: “_$!<Anniversary>!$_; print “item6.X-ABRELATEDNAMES;type=pref: “$31; print “item6.X-ABLabel: “marital; print “item7.X-ABRELATEDNAMES: “$32; print “item7.X-ABLabel: “_$!<Spouse>!$_; print “item8.X-ABRELATEDNAMES: “$33; print “item8.X-ABLabel: “salutation; print “item9.X-ABRELATEDNAMES: “$34; print “item9.X-ABLabel: “member?; print “item10.X-ABRELATEDNAMES: “$35; print “item10.X-ABLabel: “status?; print “item11.X-ABRELATEDNAMES: “$36; print “item11.X-ABLabel: “gender; print “item12.X-ABRELATEDNAMES: “$37; print “item12.X-ABLabel: “age; print “END:VCARD” $38; print $38 } ‘ ~/Desktop/Import/importdata.txt > ~/Desktop/Import/LVCdirectory.vcf


But it doesn't work. I get this error message from the terminal:

awk: syntax error at source line 1
context is
{print "BEGIN:VCARD"; print "VERSION:3.0"; print "N:"$1 $2 $3 $4 $5; print >>> ? <<<
awk: illegal statement at source line 1
-bash: print: command not found
-bash: print: command not found
-bash: print: command not found
-bash: print: command not found
-bash: print: command not found
-bash: print: command not found
-bash: print: command not found
-bash: “1: command not found
-bash: print: command not found
-bash: “2: command not found
-bash: print: command not found
-bash: “3: command not found
-bash: print: command not found
-bash: “4: command not found
-bash: print: command not found
-bash: “5: command not found
-bash: print: command not found
-bash: Other: No such file or directory
-bash: “: command not found
-bash: print: command not found
-bash: print: command not found
-bash: “: command not found
-bash: 2: command not found
-bash: print: command not found
-bash: print: command not found
-bash: “7: command not found
-bash: HomePage: No such file or directory
-bash: print: command not found
-bash: “8: command not found
-bash: print: command not found
-bash: “9: command not found
-bash: print: command not found
-bash: “0: command not found
-bash: Anniversary: No such file or directory
-bash: print: command not found
-bash: “1: command not found
-bash: print: command not found
-bash: print: command not found
-bash: Spouse: No such file or directory
-bash: print: command not found
-bash: print: command not found
-bash: print: command not found
-bash: print: command not found
-bash: print: command not found
-bash: print: command not found
-bash: print: command not found
-bash: print: command not found
-bash: print: command not found
-bash: print: command not found
-bash: print: command not found
-bash: print: command not found


Note that the Labels are the names of custom fields I created in Address Book. I left this in the command thinking it might print the name of the Label in my import. But I'm way off somewhere. Again, I have no programming background, so I'm just trying to copy the format I found on the web.

Thanks for any help you can give. I just need some pointers, I'll re edit this, try it again, and post questions if it doesn't work.

You may email me at plbradford@sbcglobal.net if you desire.

Thanks!

<br>
MacBook Pro Mac OS X (10.4.8)

Feb 13, 2007 9:44 PM in response to Plub

First thing that I suspect is your command syntax, where you say:
awk -F\t

You need a blank space between the -F and the \t, like this:
awk -F \t

You might also have a problem with "special" unix characters not being properly "escaped" so that they are treated as routine text characters rather than having some special unix meaning. The next thing that I would suspect is the $ signs and the !'s, for example, in "item1.X-ABLabel:_$!<Other>!$_. The $ is usually used to denote a variable name, like $1.

So I don't know for certain whether this will work, but try "escaping" those characters, that are not "field" variables ($1, $2, $3, etc.) by putting a backslash \ in front of each and every $ and !

Also, quite by chance I just noticed this:
print “item1.TEL: “$16; item1.X-ABLabel: “_$!<Other>!$_

As a minimum, I think you need to fix that piece to read:
print “item1.TEL: “$16; print "item1.X-ABLabel: “ "_$!<Other>!$_ "
but even that is not right -- I'm thinking you at least need a new print after each semicolon separator in there, but that won't fix it because it's not immediately clear to me how to make sure all the quotes are surrounding all the literal text that they are supposed to. You may have to start building your awk command up individual print directive by individual print directive to see where your syntax finally fails.

Converting Text Files into vCard Format

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.