File Manipulation

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

I have a text file (Original.txt) that I wish to manipulate.


============================================ Original.txt

File: Complex-Lecture 1 - annotated.pdf
Annotation summary:
--- Page 10 ---
common disorders
Cataracts
Glaucoma
Macular degeneration
Conjunctivitis/iritis
Foreign body
--- Page 15 ---
Cataract
clouding
lens
vision impairment
--- Page 16 ---
Blurred
Glare
Distortion
veil
signs
--- Page 17 ---
Treatments
glasses
bifocals
magnification
lighting
surgery
--- Page 18 ---
surgery
removal
lens
replacement
implantable lens

-------------------
So, the format is pretty much, that it has annotations taken from each page of a pdf.


-----------------------------------
The result I am seeking is as seen below,in Processed.txt

============================================ Processed.txt
File: Complex-Lecture 1 - annotated.pdf
Annotation summary:

Page 10: common disorders,Cataracts,Glaucoma,Macular degeneration,Conjunctivitis/iritis,Foreign body
Page 15: Cataract,clouding,lens,vision impairment
Page 16: Blurred,Glare,Distortion,veil,signs
Page 17: Treatments,glasses,bifocals,magnification,lighting,surgery
Page 18: surgery,removal,lens,replacement,implantable lens

------------------------------------------------

Basically, Im trying to get all lines that "belong" to a Page, to be on the same line, as that Page.
So, for example, if there are 5 lines directly after Page 15, but before Page 16, then those 5 lines "belong" to Page 15, and as such, I want them placed on the same line as Page 15, with each of those lines, separated by a comma.

I hope this makes sense.

Any help greatly appreciated.
annotations.jpg
LVL 1
Simon336697Asked:
Who is Participating?

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

x
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.

oBdACommented:
How about this:
@echo off
setlocal enabledelayedexpansion
set InFile=D:\Temp\Original.txt
set OutFile=D:\Temp\Processed.txt
if exist "%OutFile%" del "%OutFile%"
set /a i = 0
for /f "delims=" %%a in ('type "%InFile%"') do (
	set /a i += 1
	echo %%a
	>>"%OutFile%" echo %%a
	if !i!==2 goto HeaderEnd
)
:HeaderEnd
echo.
>>"%OutFile%" echo.
set Page=
set Annotations=
for /f "skip=2 delims=" %%a in ('type "%InFile%"') do (
	set Line=%%a
	if "!Line:~0,9!"=="--- Page " (
		if defined Page (
			echo !Page!: !Annotations:~2!
			>>"%OutFile%" echo !Page!: !Annotations:~2!
			set Annotations=
		)
		set Page=!Line:~4!
		set Page=!Page:~0,-4!
	) else (
		set Annotations=!Annotations!, %%a
	)
)
echo !Page!: !Annotations:~2!
>>"%OutFile%" echo !Page!: !Annotations:~2!

Open in new window

0

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
Simon336697Author Commented:
Hi oBdA,

That script is amazing. Thank you so much.

Hi aikimark,

Thanks to you too.

I am happy with oBdAs.

Thanks to you both :>)
0
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
Scripting Languages

From novice to tech pro — start learning today.