I'm trying to write a shell script in which I need to show as output the cars and their caractheristics this way:
Car: Chevrolet Chevelle Malibu
MPG: 18.0
Cylinders: 8
...
The file I have is like this:
Car;MPG;Cylinders;Displacement;Horsepower;Weight;Acceleration;Model;Origin
Chevrolet Chevelle Malibu;18.0;8;307.0;130.0;3504.;12.0;70;US
Buick Skylark 320;15.0;8;350.0;165.0;3693.;11.5;70;US
Plymouth Satellite;18.0;8;318.0;150.0;3436.;11.0;70;US
AMC Rebel SST;16.0;8;304.0;150.0;3433.;12.0;70;US
Ford Torino;17.0;8;302.0;140.0;3449.;10.5;70;US
Ford Galaxie 500;15.0;8;429.0;198.0;4341.;10.0;70;US
Chevrolet Impala;14.0;8;454.0;220.0;4354.;9.0;70;US
I have tried doing this
#! /bin/bash
i=1
line=`wc -l < cars2.csv`
while [ $i -le $line ]
do
name=`head -$i cars2.csv | tail -1 | cut -d: -f1`
mpg=`head -$i cars2.csv | tail -1 | cut -d: -f2`
echo "Name: $name"
echo "MPG: $mpg "
let i=i+1
done
I've just done this but it doesn't work the way I want, for each echo it prints the whole line like this:
Name: Chevrolet Chevelle Malibu;18.0;8;307.0;130.0;3504.;12.0;70;US
MPG: Chevrolet Chevelle Malibu;18.0;8;307.0;130.0;3504.;12.0;70;US