I'm receiving a list of operating systems, one per line, such as:
alpine/3.13
alpine/edge
alt/Sisyphus
alt/p9
apertis/v2019.5
I need to massage each line into two parameters to yield:
lxc launch images:alpine/3.13 alpine-3-13
lxc launch images:alpine/edge alpine-edge
lxc launch images:alt/Sisyphus alt-Sisyphus
lxc launch images:alt/p9 alt-p9
lxc launch images:apertis/v2019.5 apertis-v2019-5
and then run those commands. Note the second parameter has had everything non-alphanumeric switched to hyphens. I came up with the following:
echo alpine/3.13 | sed 'h;s#[/.]#-#g;x;G;s/\n/ /' | xargs -ti lxc launch images:{}
Unfortunately, although the command that xargs runs looks correct, instead of passing two arguments to lxc, xargs passes the entire thing as a single argument, so lxc tries to download an image named "alpine/3.13 alpine-3-13", instead of downloading the image named alpine/3.13 and using it to create a container named alpine-3-13.
Is there a way to pass lxc two separate arguments?
Example output:
# echo alpine/3.13 | sed 'h;s#[/.]#-#g;x;G;s/\n/ /' | xargs -ti lxc launch images:{}
lxc launch images:alpine/3.13 alpine-3-13
Creating the instance
Error: Failed instance creation: The requested image couldn't be found
# lxc launch images:alpine/3.13 alpine-3-13
Creating alpine-3-13
Starting alpine-3-13
<works correctly>
Complete (working) final command based on below input from KamilCuk and markp-fuso:
lxc image list images: | grep -v cloud | grep -Po '^\| \K[^ ]+(?=.+x86_64.+CONTAINER)' | sed 'h;s#[^[:alnum:]]#-#g;x;G;s/\n/ /;s/^ */images:/' | xargs -n2 lxc launch