Combine multiple cut commands into variable assignations into one cut command Combine multiple cut commands into variable assignations into one cut command shell shell

Combine multiple cut commands into variable assignations into one cut command


The builtin read command can assign to multiple variables:

IFS=, read _ _ _ var1 var2 var3 _ <<< "$LINE"


yes, if you're ok with arrays:

var= ( $(echo $LINE | cut -d, --output-delimiter=' ' -f4-6) )

Note that that make var 0-indexed.

Though it might just be quicker and easier to turn the CSV $LINE into something that bash parenthesis understand, and then just do var = ( $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:

var= ( $( echo $LINE | awk IFS=, '{print "\"$4\" \"$5\" \"$6\""}' ) )