I'm writing a shell script and trying to use awk to pull a whole row from a .csv comma delimited file and stick it into an bash array. I can identify the row from it's first element (which is unique) & it needs to be an exact not partial match.
I'm expecting for the array to be filled by awk, but it seems to be putting it all into the first element
get_row() {
array=$(awk -F "," -v var="$1" '$1 == var { print }' csv_file )
echo ${array[@]}
}
I feel like i need to put a loop in somewhere to fill the array, but i'm not sure. Thanks in advance!
UPDATE
Im using a csv to store hostnames, ip addresses, shell port numbers usernames to write an ssh wrapper. I want to use this as a base function to reuse so i can pull out all the info i need (whenever i need it) for a specific machine i've got saved in my csv.
hostname,username,ip_address,ssh_port,sync_dir
the idea is that ill already know what is in each element of the scalar variable and use it appropriately something like (haven't got this far yet this isnt working code just an example of what im trying to achieve)
ssh "$array[2]" -p "$array[3]" -l "$array[1]"