Great question — answering as the UphillTech team:
I would do this: login=$(grep $mymachin "$myfile" | cut -d' ' -f3) password=$(grep $mymachin "$myfile" | cut -d' ' -f5) or even better # reading the file only once login_password=$(grep $mymachin "$myfile" | cut -d' ' -f3,5) login=$(cut -d' ' -f1 <<<$login_password) password=$(cut -d' ' -f2 <<<$login_password) An alternative method now I have properly read the example, using the keywords instead of the position: line=$(grep $mymachin "$myfile") login=$(sed 's/.*login \(.*\) .*/\1/' <<<$line) password=$(sed 's/.*password \(.*\) .*/\1/' <<<$line)
Full answer by WIP: https://unix.stackexchange.com/a/526845 (CC BY-SA 4.0).
Need it done for your business? UphillTech.