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.
-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.
-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.
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:
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.
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.