I'm new to BASH, and I'm a bit lost. I'm also not sure if my particular issue has been addressed before or not (apologies if it has).
I have a csv file with a table that has 3 columns. I'd like to run a loop that will repeat a certain command and, after it's completed, re-run my command and insert the next values from the table my variables pull from. I'd like this process to repeat until each value from each column of the table has been pulled (my command pulls three at a time).
Here's what I have so far:
file=$(cat /path/my_ids.csv | awk -v FS=',' '{ print $1}'| head -1 | tail -n 1 )
id1=$(cat /path/my_ids.csv | awk -v FS=',' '{ print $2}'| head -1 | tail -n 2 )
id2=$(cat /path/my_ids.csv | awk -v FS=',' '{ print $3}'| head -1 | tail -n 3 )
These are the variables I am using to call values from their respective columns in my table (my_ids.csv). My command will need to pull three values from three different columns at once each time it runs through the loop. My command is supposed to look like this once the loop is ready - all I've done to the original command is include what is in between the asterisks:
command -base **$file** -tp **$id1** -tp **$id2** -all
(The command runs from a specific program that will create a new directory (file) while averaging the other two id directories. This is why I need a loop that runs through the next value in each variable column every time that it loops.)
How can I get bash to repeat that command and move down the three columns of values on each loop occurrence?
Thanks for your help and patience!
tail -n 3sooid2has 3 last lines?cat | awkis generally wrong. Andawk | head | tailis also an anti-pattern. You shouldn't be usingawkat all to parse the line, but if you wanted to do so you could get the value from the Nth line with something likefile=$(awk 'NR==n{print $1}' n=$N FS=, /path/my_ids.csv)rather than (ab-)using cat/head/tail.