Reputation: 385
How can I write a script to convert names in a CSV file into QRCODES.
I have a CSV file called names.csv with 5000 names. I have also installed qrcode package In the folder where the csv file is I ran from bash
qrcode "John Doe" john_doe.png
That created a qrcode for John Doe.
Now I need to create 5000 more qrcodes from the CSV. I have definately no Idea, how to go about that.
I also tried running
qrcode names.csv names.png
But That created just 1 qrcode image.
Upvotes: 1
Views: 1083
Reputation: 626
Something like this?
#!/bin/bash
IFS=$'\n';
for name in $(cat names.csv); do
qrcode "$name" $(echo $name | tr ' ' '_').png;
done
IFS=$'\n' - takes new line as delimiter. Since you will have white spaces in lines, you want to set is as new line to properly run it through the loop.
tr ' ' '_' - this actually sets the output for the image name. We replace the space between the First name and the Last name into a underscore _
Upvotes: 2
Reputation: 2384
Another version - limits the use of command substitution:
#!/bin/bash
set -e
while IFS= read -r name; do
file=${name/ /_}.png
qrcode "$name" "$file"
done < names.csv
Assumes that the file names.csv
only has one "field" - each full line is a name. Also, using set -e
means that the script exits if any qrcode
invocation fails.
Upvotes: 0