Question

I have about 3400 contacts from my customer in numbers like :

+13424xxxx
+1434xxxxx

I would like to use a bash script to generate a file with a vcard for each number :

BEGIN:VCARD
VERSION:3.0
FN:customer name
N:Name;;;;
TEL;TYPE=CELL:+13242XXXX
END:VCARD

is it possible to generate a one vcard file containing those 3400 contacts ?

thanks

Was it helpful?

Solution

Sounds like you have a solution - I wrote the external post - which is really specific for dealing with Outlook CSV to Vcard using multiple data points.

A simple approach to your current query:

### snip - start of script - remove this line ###
#!/bin/bash
# use a 'here document' to create the Vcard format
## add/remove Vcard fields between the 'EOM' start/end marks
function create_vcard {
cat << EOM
BEGIN:VCARD
VERSION:3.0
FN:customer name
N:Name;;;;
TEL;TYPE=CELL:${CELL_NUMBER}
END:VCARD
EOM
}
###

IN_FILE=$1
## if IN_FILE missing show usage
if [[ "${IN_FILE}" == "" ]] ; then printf "\n\tUsage: $0 Input_file_name\n\n" ; exit 1 ; fi

OUT=${IN_FILE}.vcard
## if OUT already exists then rename
if [[ -e ${OUT} ]] ; then mv ${OUT} ${OUT}.last ; fi

for CELL_NUMBER in $(cat ${IN_FILE})
do
    create_vcard >> ${OUT}
done
ls -l ${OUT}
### snip - end of script ###

If you have more data fields to work with then the orignal post which uses Awk may be a better

approach.

:)
Dale

OTHER TIPS

Let's say you have those numbers stored in a file named numbers.txt, one number per line.

Then you can do (in pure bash):

cat numbers.txt| while read LINE; do echo -e "BEGIN:VCARD...CEL:$LINE\nEND:VCARD"; done

i.e., you're saving each line into the $LINE pasting it inside static text.

You can redirect that to a file with > (truncate target and write into it) or >> (append to target) followed by the name you want to write into.

Realistically, you'd have multiple columns (not just numbers, but also names, and other data). Pure bash is not good at that, and in bash scripting, people use helper utilities such as awk to parse text files with such tables in them (another language to learn).

Personally, I think it'd be better and quicker for you to adapt the offered csv solution, or to whip out your own with PHP.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top