Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

csvtovcf.md added #65

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions ebook/en/content/024-csvtovcf.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# CSV To VCF

The script given below basically used to convert CSV file into VCF format. <br>
The csv file must be in the format of name,ID,Mobile no. and Age of that person. <br>
It read the file and generate temp.vcf file which contain the details in VCF format. <br>

```bash
#!/bin/bash

input_file=$1
temp="$(basename "$1" | sed 's/\(.*\)\..*/\1/')"
if [ ! -f $input_file ]
then
echo "The input csv file does not exists!!!"
exit
fi

count=1
output_file="$temp.vcf"
touch $output_file
while IFS="," read col1 col2 col3 col4
do
if [ $count -eq 1 ]
then
count=$((count+1))
continue
fi
echo "BEGIN:VCARD" >> $output_file
echo "VERSION:1" >> $output_file
echo -e "\nName : $col1" >> $output_file
echo "ID : $col2" >> $output_file
echo "Mobile : $col3" >> $output_file
echo -e "Age : $col4 \n" >> $output_file
echo "END:VCARD" >> $output_file

count=$((count+1))
done < $input_file
```

<br>

Just copyt the code in .sh file then run the file followed by the .csv file name: <br>
for eg.
```bash
csvtovcf.sh info.csv
```