Link to home
Start Free TrialLog in
Avatar of Watnog
WatnogFlag for Belgium

asked on

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.

Avatar of shajithchandran
shajithchandran
Flag of India image

couldnt understand the question.. can you give some more details.. with examples
Avatar of Watnog

ASKER

See file attached.
What syntax would be needed to extract for instance all data concerning UTLAPPP03.
Thanks.
example.txt
Avatar of medvedd
medvedd

sed -n '/UTLAPPP03/,/Total/p' example.txt
Avatar of Watnog

ASKER

Thank you! That works great. Could different search strings be combined, let's say look for UTLAPPP03 but also for UTLAPPP01?
ASKER CERTIFIED SOLUTION
Avatar of medvedd
medvedd

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Watnog

ASKER

Great.