Skip to content
Advertisement

Specify source line from csv when calling up/creating an array

I have a csv with data such as:

JavaScript

I’ve written some code to turn each field into a variable, and also to create an array out of each word in field 2 (f2):

JavaScript

My problem is now, because the file contains multiple lines I need some way of naming each array according to the line of data it was created from. At the moment when I echo ${arr[0]} it prints the first word from f2 of every line, when I would like to be able to be able to call up a specific line. EDIT: To clarify (sorry I’m a noob and didn’t explain very well) I would like to somehow change my code so that rather than creating an array for each separate word in f2 throughout the file, I want to create an array for each word in f2 on a line by line basis and somehow be able to display the line of the csv it came from.

Advertisement

Answer

My answer is just guessing, but it maybe can help you. Maybe clarify your question that so I can address my answer better.

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement