Click here to Skip to main content
15,895,777 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Block of data starts with "<SUBBEGIN" and ends with "<SUBEND"

I only want to list SUBSCRIBERIDENTIFIER which only have one or combination of these SUBSCRIPTION(5093264, VOIPBurn, 2000018).

Any SUBSCRIPTION that is not in the bracket above should not be printed/listed even if it is combined in the block of data with any of the SUBSCRIPTION in the bracket above). The block of data are as below. They are saved in a text file.

<SUBBEGIN
	SID:28E4
	SUBSCRIBERIDENTIFIER:234817524
	GBRUL:0
	GBRDL:0
	SUBSCRIPTION:5093264&733D8E01CA0E270D&1&FFFFFFFFFFFFFF
	MAXOFFLINEDAYS:0
<SUBEND
<SUBBEGIN
	SID:28E5
	SUBSCRIBERIDENTIFIER:234809156
	GBRUL:0
	GBRDL:0
	SUBSCRIPTION:2000018&73152E10C5625511&1&20170419145702
	MAXOFFLINEDAYS:0
<SUBEND
<SUBBEGIN
	SID:28E6
	SUBSCRIBERIDENTIFIER:234817365
	GBRUL:0
	GBRDL:0
	SUBSCRIPTION:VOIPBurn&73152E10C5625511&1&2017041914570
	MAXOFFLINEDAYS:0
<SUBEND
<SUBBEGIN
	SID:28E7
	SUBSCRIBERIDENTIFIER:234909599
	GBRUL:0
	GBRDL:0
	SUBSCRIPTION:VOIPBurn&73152E10C5625511&1&2017041914465
	SUBSCRIPTION:5083038&733DAA081F1DC70B&1&FFFFFFFFFFFFFF
	MAXOFFLINEDAYS:0
<SUBEND
<SUBBEGIN
	SID:28E8
	SUBSCRIBERIDENTIFIER:234818752
	GBRUL:0
	GBRDL:0
	SUBSCRIPTION:2000018&73159A0C66F20A0A&1&20170322155953
	SUBSCRIPTION:5093264&733D8E01CA0E270D&1&FFFFFFFFFFFFFF
	SUBSCRIPTION:2000020&73159E0C85F20A0A&1&FFFFFFFFFFFFFF
	MAXOFFLINEDAYS:0
<SUBEND
<SUBBEGIN
	SID:28E9
	SUBSCRIBERIDENTIFIER:234818465
	GBRUL:0
	GBRDL:0
	SUBSCRIPTION:5093264&73159A0C66F20A0A&1&20170516214656
	MAXOFFLINEDAYS:0
<SUBEND
<SUBBEGIN
	SID:28F0
	SUBSCRIBERIDENTIFIER:234818440
	GBRUL:0
	GBRDL:0
	SUBSCRIPTION:5093264&73159A0C66F20A0A&1&20170516214656
	SUBSCRIPTION:2000018&73159A0C66F20A0A&1&20170516214656
	MAXOFFLINEDAYS:0
<SUBEND


Result output like this:
SUBSCRIBERIDENTIFIER:234817524 SUBSCRIPTION:5093264
SUBSCRIBERIDENTIFIER:234809156 SUBSCRIPTION:2000018
SUBSCRIBERIDENTIFIER:234817365 SUBSCRIPTION:VOIPBurn
SUBSCRIBERIDENTIFIER:234818465 SUBSCRIPTION:5093264
SUBSCRIBERIDENTIFIER:234818440 SUBSCRIPTION:5093264 SUBSCRIPTION:2000018


What I have tried:

No I have not tried. I'm new to Linux
Posted
Updated 9-Jul-18 22:02pm
v2
Comments
Richard MacCutchan 22-Mar-18 5:02am    
This has nothing to do with Linux, it is a simple text matching problem. You just need to read each section between SUBBEGIN and SUBEN, and extract the items you are interested in by comparing the text with the values you need.

1 solution

Can be done easily with a few basic cli utilities. Although this wouldn't be the nicest solution to update/maintain. If your problem is actually any more complicated than this, or will need to be updated in future I'd recommend you use a high level scripting language like Ruby or Python instead.

Assuming a filename of block.text you can extract the lines you care about:
sed '/\(<SUBEND\|SUBSCRIBERIDENTIFIER\|SUBSCRIPTION\)/!d' block.txt |\

Truncate the Ampersands
cut -f1 -d"&" |\

Delete newlines, tabs, etc
tr '\t\r\n' ' ' |\

Replace the <SUBEND with newlines
sed 's/<SUBEND /\n/g' |\

Tidy up leading whitespace and doublespaces
sed 's/^ \+//g' |\
sed 's/ \+/ /g'
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900