Script to create unique look-up for headers for a Dictionary

I have a text file in UTF-8 format which has the following data structure

HEADWORD=gloss1,gloss2,gloss3 etc

I want to convert it so that all the glosses of the HeadWord appear on separate lines

HEADWORD=gloss1
HEADWORD=gloss2
HEADWORD=gloss3

An example will illustrate the requirement
INPUT

 =regain consciousness.
=clever, intelligent; skilful; alert, vigilant; cautious; understanding, sensible.
 =boast,(try to) be clever.
 =boast,(try to) be clever.
 =boast,(try to) be clever.
 =boast,(try to) be clever.
 =be cautious,be vigilant,be alert.
=cleverness, vigilance
=noise, uproar, tumult, public talk or discussion, excitement, agitation, alarm, consternation.
=uproar, tumult, excitement, alarm.
=noise, uproar, tumult, public talk or discussion, excitement, agitation, alarm, consternation.

The Output would be

=clever
=intelligent
=skilful
=alert
=vigilant
=cautious
=understanding
=sensible.
 =boast
 =(try to) be clever.
 =boast
 =(try to) be clever.
 =boast
 =(try to) be clever.
 =boast
 =(try to) be clever.
 =be cautious
 =vigilant or alert.
=cleverness
=vigilance
=etc.
=noise
=uproar
=tumult
=public talk or discussion
=excitement
=agitation
=alarm
=consternation.
=uproar
=tumult
=excitement
=alarm
=noise
=uproar
=tumult
=public talk or discussion
=excitement
=agitation
=alarm
=consternation

At present I use macros which identify the delimiter, copy the text between two delimiters, paste it on next line, preface it with the headword and continue the operation till end of line and repeat the same for the next line. Since the file is huge a PERL or AWK script would help.
I work under Windows and UNIX type solutions do not work for me unfortunately.
Many thanks in advance.

May be this?

echo HEADWORD=gloss1,gloss2,gloss3 | awk -F "[,=]" '{for (i=2;i<=NF;i++) {$i=$1"="$i;print $i}}'

Hello,
Many thanks for your help.
I tried the script you provided but got the following output on the sample file:

 =regain consciousness.
==regain
=consciousness.
=clever, intelligent; skilful; alert, vigilant; cautious; understanding, sensible.
=clever,=intelligent;
=clever,=skilful;
=clever,=alert,
=clever,=vigilant;
=clever,=cautious;
=clever,=understanding,
=clever,=sensible.
 =boast,(try to) be clever.
==boast,(try
=to)
=be
=clever.
 =boast,(try to) be clever.
==boast,(try
=to)
=be
=clever.
 =boast,(try to) be clever.
==boast,(try
=to)
=be
=clever.
 =boast,(try to) be clever.
==boast,(try
=to)
=be
=clever.
 =be cautious,be vigilant,be alert.
==be
=cautious,be
=vigilant,be
=alert.
=cleverness, vigilance
=cleverness,=vigilance
=noise, uproar, tumult, public talk or discussion, excitement, agitation, alarm, consternation.
=noise,=uproar,
=noise,=tumult,
=noise,=public
=noise,=talk
=noise,=or
=noise,=discussion,
=noise,=excitement,
=noise,=agitation,
=noise,=alarm,
=noise,=consternation.
=uproar, tumult, excitement, alarm.
=uproar,=tumult,
=uproar,=excitement,
=uproar,=alarm.
=noise, uproar, tumult, public talk or discussion, excitement, agitation, alarm, consternation.
=noise,=uproar,
=noise,=tumult,
=noise,=public
=noise,=talk
=noise,=or
=noise,=discussion,
=noise,=excitement,
=noise,=agitation,
=noise,=alarm,
=noise,=consternation.

Did I cut and paste wrongly the code.
Thanks again but it did not work.

wait....

---------- Post updated at 08:30 PM ---------- Previous update was at 08:18 PM ----------

$ awk -F= '{a=$1;sub(a"=","");$0=$0;FS="[;,=]";for(i=2;i<=NF;i++)print a" ="$i}' a.txt
 = intelligent
 = skilful
 = alert
 = vigilant
 = cautious
 = understanding
 = sensible.
  =(try to) be clever.
  =(try to) be clever.
  =(try to) be clever.
  =(try to) be clever.
  =be vigilant
  =be alert.
 = vigilance
 = uproar
 = tumult
 = public talk or discussion
 = excitement
 = agitation
 = alarm
 = consternation.
 = tumult
 = excitement
 = alarm.
 = uproar
 = tumult
 = public talk or discussion
 = excitement
 = agitation
 = alarm
 = consternation.

1 Like

Many thanks for the script. It works beautifully and handled 50,000 dictionary entries in no time