How can I manipulate text in bash? [closed]

With awk:

awk 'BEGIN{FS="[ ,]"; OFS=","} {for (i=2; i<=NF; i++) print $i,$1}' file

Output:

foo,ted
bar,ted
zoo,ted
ket,john
ben,john

See: 8 Powerful Awk Built-in Variables – FS, OFS, RS, ORS, NR, NF, FILENAME, FNR

Leave a Comment