Making a summary text file.

Hi guys,
I hope you are well and can help.

I have a text file called "sorted_a.txt".
The format of this file is as follows:

--------------------------------------------------------------------------------------------------- sorted_a.txt
abalone -- this is the definition of abalone;
adversary -- this is the defintion;
aeroplane -- this is another meaning;
at the park -- this is at the park;


I'd like to produce a script that will....

Examine the contents of soreted_a.txt, and treat each block of word or words before the "--" is treated as a single "chunk" per line.
Each of these chunks is copied to a new file called "summary_sorted_a.txt"
Each chunk in this new file is separated from each other by a comma.
The last chunk of the new file will be ended by a semicolon.

An example of its output using the above sorted_a.txt file would be:

--------------------------------------------------------------------------------------------------- summary_sorted_a.txt
abalone, adversary, aeroplane, at the park;

Any help greatly appreciated.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Surranoapplication managerCommented:
Hello Simon,
Try this:
cat sorted_a.txt | awk -F' *--' '
  NR>1 {printf ", "} 
  {printf $1} 
  END { print ";" }'

Open in new window

Note that I trimmed the first field by adding "zero or more spaces" to the field separator.
NVITEnd-user supportCommented:
@echo off
for /f "delims=-" %%a in (sorted_a.txt) do if "!x1!" equ "" (set x1=%%a) else (set x1=!x1!,%%a)
set x1=%x1: ,=,%;
set x1=%x1: ;=%;
echo %x1% > summary_sorted_a.txt & type summary_sorted_a.txt

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Surranoapplication managerCommented:
... and the good news is that GNU tools like cat and awk are available for windows as well, both in native and unix-like flavours.
Simon336697Author Commented:
Guys thanks so much again. That works great. Thank you .
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.