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
More Related Contents:
- How to merge every two lines into one from the command line?
- Grep output with multiple Colors?
- How to delete rows from a csv file based on a list values from another file?
- How to grep for case insensitive string in a file?
- how to print n words of context while searching text [closed]
- Convert 11/2/1998 to 110298 [duplicate]
- Some troubles with using sed and awk [closed]
- How can I do a recursive find/replace of a string with awk or sed?
- Bash tool to get nth line from a file
- Fastest way to find lines of a file from another larger file in Bash
- Extraction of data from a simple XML file
- Remove first N lines of a file in place in unix command line
- How to add to the end of lines containing a pattern with sed or awk?
- Check if all of multiple strings or regexes exist in a file
- How to remove double-quotes in jq output for parsing json files in bash?
- How to find/replace and increment a matched number with sed/awk?
- how to delete the duplicate lines in file except the first matched line
- find difference between two text files with one item per line [duplicate]
- Using grep to search for hex strings in a file
- How to append a string at end of a specific line in a file in bash [duplicate]
- How to strip out all of the links of an HTML file in Bash or grep or batch and store them in a text file
- using bash (sed/awk) to extract rows AND columns in CSV files?
- How can I remove the first line of a text file using bash/sed script?
- How to get the part of a file after the first line that matches a regular expression
- Piping tail output though grep twice
- Use awk to find average of a column [duplicate]
- How to show only next line after the matched one?
- Use sed to replace all backslashes with forward slashes
- How to match a single quote in sed
- How to insert a new line character after a fixed number of characters in a file