Watnog
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.
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.
couldnt understand the question.. can you give some more details.. with examples
ASKER
See file attached.
What syntax would be needed to extract for instance all data concerning UTLAPPP03.
Thanks.
example.txt
What syntax would be needed to extract for instance all data concerning UTLAPPP03.
Thanks.
example.txt
sed -n '/UTLAPPP03/,/Total/p' example.txt
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Great.