0

I have a csv file that looks like this.

TeamName,Metric,ON,OFF
name,469388,84,20
unassigned,1442,1,375
name2,61306,11,0
name3,245556,34,13
name4,918989,123,37
name5,143600,22,11
NONE,327208,36,11
name6,1010223,98,6
name7,130533,9,1
name8,8155,1,2
name10,327127,62,19
name11,327595,59,17

I would like to assign the first column (names) to a string named "team" and the second column (metric) to a string named "metric". The script should move line by align and re-assign the 'team' and 'metric' variables, overnighting the previous assignments.

The script should skip the first line.

I am researching how to do this now but any help would be appreciated.

jsirianni
  • 73
  • 2
  • 5
  • 1
    Possible duplicate of [Read a file line by line assigning the value to a variable](http://stackoverflow.com/questions/10929453/read-a-file-line-by-line-assigning-the-value-to-a-variable) Also, [How to split a variable by delimiter](http://stackoverflow.com/questions/918886/how-do-i-split-a-string-on-a-delimiter-in-bash) or something similar. Also, depending on what you are doing with the first and second column, `awk` might be a good one stop shop for your script. – JNevill Dec 13 '16 at 15:02
  • Why bash and not sed? – Mike Samuel Dec 13 '16 at 15:14
  • #/bin/bash filename="dat" tail --lines=+2 $filename | while read LINE do team=`echo "$LINE" | cut -d "," -f1` metr=`echo "$LINE" | cut -d "," -f2` echo "team: $team, metric: $metr" done – chris01 Dec 13 '16 at 15:46

0 Answers0