SED to print from [first occurance] to [last occurance]

Dear Experts,

I have a 84K rows file of which I need to filter out certain data.
I would need all lines starting from a string to the last occurence of string but including the first occurrence of [Total] after that last ocurrence...

File would look like this:

xxxxxxx
xxxxxxxxxx
xxx
xx
xxxx

FIRST OCCURENCE OF STRING [AAA-111]  
 adfsdf
sdfsdd
TOTAL

SECOND OCCURENCE OF STRING [AAA-111]
sfdsfsdfdfd
sdf

sdfffsf
TOTAL

THIRD OCCURENCE OF STRING [AAA-111]
dfsfsdaf

LAST OCCURENCE OF STRING [AAA-111]
sdfsdf
sdfsd

sdfsd
sdfsdf

sdfsd

TOTAL

xxxxxxxxxxx
xxxxxxx
xxxxxxxxxxxx

xxxxxxxxxxxx


So I would need everything that is between the x's
The first occurence and the last occurence are grouped.

Hope you can help.

WatnogAsked:
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.

shajithchandranCommented:
couldnt understand the question.. can you give some more details.. with examples
0
WatnogAuthor Commented:
See file attached.
What syntax would be needed to extract for instance all data concerning UTLAPPP03.
Thanks.
example.txt
0
medveddCommented:
sed -n '/UTLAPPP03/,/Total/p' example.txt
0
Become a Certified Penetration Testing Engineer

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

WatnogAuthor Commented:
Thank you! That works great. Could different search strings be combined, let's say look for UTLAPPP03 but also for UTLAPPP01?
0
medveddCommented:
Yes, it could be any regular expression between //. For UTLAPPP01 and UTLAPPP03:

sed -n '/UTLAPPP0[13]/,/Total/p' example.txt
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
WatnogAuthor Commented:
Great.
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
Shell Scripting

From novice to tech pro — start learning today.