I have a CSV that I'm using as a data source. I need to split the lines on the newline character ('\n') into a variable called 'lines', and I need to split the semi-colon (';') delimited values in each line into a variable called 'items'.
I want to be able to check the first value on a line and, if it equals the input value in an input box, I want to add this line, with the semi-colon delimiter between the values, to a new variable called newData. If it's not equal to the value in the input box, I want to exclude it.
I basically want to filter out each line where the first value doesn't equal the value I'm searching for.
Here's a sample of the data (assume a newline ('\n') character after each line):
"ID";"Date";"Time";"Status"
"1";"2013.01.01";"10:03 AM";"Active"
"1";"2013.01.05";"07:45 AM";"Active"
"2";"2013.01.03";"9:12 PM";"Active"
"2";"2013.01.11";"6:37 AM";"Inactive"
"1";"2013.01.22";"12:57 PM";"Inactive"
I can split off the first header line and that won't be included in the results I'm seeking. If my search is on the ID column and the search value is 1, I want to only return the lines where the ID equals 1 and want it to match the format above (sans header line). Conversely, if the search value is 7, I would only return either no lines or just the header line.
All I've been able to do so far is split the lines from the data I'm importing (all of this code I found, I'm really not that familiar with javascript or jQuery):
$.get("myFile.csv", function(data) {
data = data.replace(/"/g, "");
var lines = data.split('\n');
var first = lines.shift().split(';');
});
// HTML Input Box
<input id="search_box" type="text">
<button id="btn_search">Search</button>
Thanks.