Working with CSV files — Bash Scripting

Now we know how to format the output in color, lets see what we may use this for. Searching though CSV files and highlighting names or products is one option and we will look at a script that searches a user directory in CSV format for users and their job roles. The GNU command grep will be useful to us in this search for -A3 , rows after and -B1 rows before.

We have been used to using read in scripts before but we can populate more than one variable if needed:

while read user job uid location

Here we read in our loop 4 variables: user through to location , these make up the schema of the CSV files that we read. The whole script is below :