pythonbashawk

Pair data located in the same string, AWK or other


I have a file with strings like this

1A,1B,1C,   2A,2B,2C,

between the group "1" and the group "2" there is a tab (each string has a different number of elements inside the file); I would need to pair the "A", "B", and "C", and move each pair in a new line; for e.g.

1A-2A
1B-2B
1C-2C

I was looking with AWK or BASH but I can not come out. Any help, thanks.


Solution

  • Perl solution:

    perl -F'/\t/' -lne '@c = map [split /,/, $_], @F;
                        print "$c[0][$_]-$c[1][$_]" for 0 .. $#{ $c[0] }
                       ' < input_file