I have a file with plain text. This file contains a list like this:@Joe, @211,@Bob Nelson, @132,@Jack Sierra, @3422,@Walt Robert, @14,The list goes on and on with thousands of names... I need to switch the elements order and transform this list to@211, @Joe,@132, @Bob Nelson,@3422, @Jack Sierra,@14, @Walt Robert,How do I do it from terminal?
changing the order of items in a list
text processing
This one will work with strings with spaces in it:sed 's/\(@[^]*\), \(@[^]*\)/\2, \1/' input.txtHow it works:sed - (s)tream (ed)itor will execute (s)ubstosute command on each line of input, and replaces \(@[^]*\), \(@[^]*\) with the \2, \1.The \2 means second match (from the second braces)The \1 means first match (from the first braces).Braces must be escaped, so we have \( and \). Inside we look for @ character, then  character and then [^] any characters different than  repeated anytime and then the  character.Then we expect , comma followed by the space and similar second group for the \2.