Transpose comma delimited data in rows to columns

Hello,
I have a bilingual database with the following structure

a,b,c=d,e,f

The right half is in a Left to right script and the second is in a Right to left script as the examples below show
What I need is to separate out the database such that the first word on the left hand matches the first word on the right hand and creates a wordlist of unique words

a=d
b=e
c=f

I wrote the following script in awk to handle this issue but it does not seem to work:

BEGIN{FS="="}
{n=split($1,a," ");split($2,b," ");for (i=1;i<=n;i++) print a"="b}

But it doesn't seem to work and spews out garbage. Please help.
My work environment is Windows and hence dos. A Perl script would also help.

Many thanks for your help

Are a,b,c, etc., separated by commas? Your code, your description, and you sample output do not jibe., as far as I can see.

Can you post one or two lines of actual real data (or dummied up if exposing data is an issue), then post the expected output based on the input data. So, two lines would produce six lines of output?

Sorry.
I should have mentioned that the words on each side are delimited by a comma.

a,b,c=d,e,f

Given this input,the resultant output would be 3 pairs of entities

a=d
b=e
c=f

Here is a live data sample. The left hand is to be read as Left to Right and the Right hand side is Right to left.

=
,,=,,
=
=
,,=,,
,,,=,,,

Many thanks for your query and interest

Try changing:

{n=split($1,a," ");split($2,b," ");for (i=1;i<=n;i++) print a"="b}

to:

{n=split($1,a,",");split($2,b,",");for (i=1;i<=n;i++) print a"="b}

When you have words separated by commas, splitting on spaces doesn't work.

Or you could try the simpler version:

awk -F'[,=]' '{o = NF / 2;for(i = 1; i <= o; i++) print $i "=" $(i + o)}' file
1 Like

Many thanks for correcting the code. I tested both and the second solution is faster