User Tools

Site Tools


public:parsing_a_csv_file_with_bash

Parsing a CSV File with Bash

You can easily parse CSV files with bash. In this example script, I generate QR codes using qrencode as an example. As a source I use following very simple CSV file called list.csv:

Google,https://www.google.com
Yahoo,https://www.microsoft.com
Microsoft,https://www.microsoft.com

We then parse the CSV file and execute qrencode with the parameters extracted from each line:

#!/bin/bash
 
while IFS=, read -r name url
do
  qrencode -o "${name}.png" "${url}"
done

We can run this script like this:

bash script.sh < list.csv

Note that IFS defines the intra field separator. That's the character to define where a new field starts.

References

public/parsing_a_csv_file_with_bash.txt · Last modified: by thomas

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki