0

I have to manipulate a CSV file (formed by cars and some of their characteristics) and output something like:

The car name is $car_name

Every time I run the program I want to show a different car. This is the code I have for the moment:

#! /bin/bash
lines_total=`wc -l < cars.csv`
car_name=

let line_number=$(( (RANDOM % $lines_total) + 1 ))

echo "The car name is `$car_name`"

What should I write as value of the $car_name variable so that it shows a random car every time?

The cars.csv content is like this, each line is a different car with their own properties, for example:

Car;Year;Origin;Max Speed;Miles per Gallon

  • Please [edit] your question, show a reasonable sized example of your input file `cars.csv` and explain the meaning of the columns/values. – Bodo Dec 02 '21 at 15:51

0 Answers0