Given a previously defined $LINE in a shell script, I do the following
var1=$(echo $LINE | cut -d, -f4)
var2=$(echo $LINE | cut -d, -f5)
var3=$(echo $LINE | cut -d, -f6)
Is there any way for me to combine it into one command, where the cut is run only once?
Something like
var1,var2,var3=$(echo $LINE | cut -d, -f4,5,6)
yes, if you’re ok with arrays:
Note that that make
var0-indexed.Though it might just be quicker and easier to turn the CSV
$LINEinto something that bash parenthesis understand, and then just dovar = ( $LINE ).EDIT: The above will cause issues if you have spaces in your $LINE… if so, you need to be a bit more careful, and AWK might be a better choice to add quotes: