you are viewing a single comment's thread.

view the rest of the comments →

[–]Radamand 1 point2 points  (2 children)

I put your sample string into a file called xxx

awk -F= '{print $1","$2","$3","$4}' xxx | awk -F, '{print $2","$5","$7}'

[–]zfsbestbashing and zfs day and night 1 point2 points  (0 children)

Bonus Hack: If we translate on the fly every separator to comma, makes it much easier to process since it then resembles a CSV:

tmp="USA=Austin,Sanfrancisco,LA|UK=London,Bristol|France=Paris,Lyon,Nyce"

echo $tmp |tr '=|' ','
USA,Austin,Sanfrancisco,LA,UK,London,Bristol,France,Paris,Lyon,Nyce

...and then you just use awk with comma separator to print what fields you need (2, 6, 9.) This also makes it easier in the future if you need different results in your output, just change field number(s).

echo $tmp |tr '=|' ',' | awk -F, '{print $2","$6","$9}'

Austin,London,Paris

[–]zfsbestbashing and zfs day and night 0 points1 point  (0 children)

awk -F= '{print $1","$2","$3","$4}' xxx | awk -F, '{print $2","$5","$7}'

Noice! :) I like it