Reputation: 692
I am new to using awk i want to separate string contains spaces.
vboxmanage list vms
this is my command and its output is below
"VMOne" {5559eb92-2665-4c52-a75d-b57c248c74db}
"VM Second" {9bc754f8-4dfd-44e5-9469-dd824d438832}
my expected output is VMOne;VM Second
below is some thing i have tried
vboxmanage list vms | awk '{print $1,";"}' | sed 's/"//g' | awk -vORS="" '1'
but, it gives me output like VMOne ;VM ;
it cuts the second
word and add a space before ;
any suggestion will helpfull thanks
Upvotes: 1
Views: 668
Reputation: 75588
awk -F\" '{ printf (NR > 1 ? ";%s" : "%s"), $2 } END { if (NR) print "" }' file
Output:
VMOne;VM Second
if (NR)
is optional if expected input always has lines. You can also remove the END
block completely if you don't need to terminate the output with newline on the end.Upvotes: 3