Iurii
Iurii

Reputation: 1795

SED delete repeated part of file

I have next configuration file:

[DEFAULT]
SenderCompID=BARXPB
ConnectionType=acceptor
SocketAcceptPort=4444
FileStorePath=store
FileLogPath=/apps/test
HttpAcceptPort=3333
TransportDataDictionary=../../share/quickfix/FIXT11.xml
AppDataDictionary.FIX.4.0=../../share/quickfix/FIX40.xml
AppDataDictionary.FIX.4.1=../../share/quickfix/FIX41.xml
AppDataDictionary.FIX.4.2=../../share/quickfix/FIX42.xml
AppDataDictionary.FIX.4.3=../../share/quickfix/FIX43.xml
AppDataDictionary.FIX.4.4=../../share/quickfix/FIX44.xml
AppDataDictionary.FIX.5.0=../../share/quickfix/FIX50.xml
AppDataDictionary.FIX.5.0SP1=../../share/quickfix/FIX50SP1.xml
AppDataDictionary.FIX.5.0SP2=../../share/quickfix/FIX50SP2.xml
StartTime=00:00:00
EndTime=23:59:59
StartDay=sun
EndDay=sat

[SESSION]
TargetCompID=TUDOR-TEST
BeginString=FIX.4.4
DataDictionary=../../share/quickfix/FIX44.xml

[SESSION]
TargetCompID=SECOR-TEST
BeginString=FIX.4.4
DataDictionary=../../share/quickfix/FIX44.xml

[SESSION]
TargetCompID=ORTUS-TEST
BeginString=FIX.4.4
DataDictionary=../../share/quickfix/FIX44.xml

[SESSION]
TargetCompID=CRABEL-TEST
BeginString=FIXT.1.1
DefaultApplVerID=FIX.5.0SP2

[SESSION]
TargetCompID=FXCM-TEST
BeginString=FIXT.1.1
DefaultApplVerID=FIX.5.0SP2

[SESSION]
TargetCompID=HIROSEIIJ-TEST
BeginString=FIX.4.4
DataDictionary=../../share/quickfix/FIX44.xml

[SESSION]
TargetCompID=KNIGHT-TEST
BeginString=FIXT.1.1
DefaultApplVerID=FIX.5.0SP2

My task is to change all [SESSION] tags by for example only one [SESSION] with CRABEL-TEST record, so the final configuration file should be look like this:

[DEFAULT]
SenderCompID=BARXPB
ConnectionType=acceptor
SocketAcceptPort=4444
FileStorePath=store
FileLogPath=/apps/test
HttpAcceptPort=3333
TransportDataDictionary=../../share/quickfix/FIXT11.xml
AppDataDictionary.FIX.4.0=../../share/quickfix/FIX40.xml
AppDataDictionary.FIX.4.1=../../share/quickfix/FIX41.xml
AppDataDictionary.FIX.4.2=../../share/quickfix/FIX42.xml
AppDataDictionary.FIX.4.3=../../share/quickfix/FIX43.xml
AppDataDictionary.FIX.4.4=../../share/quickfix/FIX44.xml
AppDataDictionary.FIX.5.0=../../share/quickfix/FIX50.xml
AppDataDictionary.FIX.5.0SP1=../../share/quickfix/FIX50SP1.xml
AppDataDictionary.FIX.5.0SP2=../../share/quickfix/FIX50SP2.xml
StartTime=00:00:00
EndTime=23:59:59
StartDay=sun
EndDay=sat

[SESSION]
TargetCompID=CRABEL-TEST
BeginString=FIXT.1.1
DefaultApplVerID=FIX.5.0SP2

Does it possible to make by SED? I used this expression

sed '/SESSION//CRABEL-TEST/,/SESSION/s/,SESSION,/,CRABEL-TEST,/g'

but no luck.

Thanks in advance.

Upvotes: 0

Views: 51

Answers (1)

Avinash Raj
Avinash Raj

Reputation: 174706

Try the below GNU awk command,

$ awk -v RS="\n\n" '/^\[DEFAULT\]/{print} /^\[SESSION\]/&&/CRABEL-TEST/{print}' ORS="\n\n" file
[DEFAULT]
SenderCompID=BARXPB
ConnectionType=acceptor
SocketAcceptPort=4444
FileStorePath=store
FileLogPath=/apps/test
HttpAcceptPort=3333
TransportDataDictionary=../../share/quickfix/FIXT11.xml
AppDataDictionary.FIX.4.0=../../share/quickfix/FIX40.xml
AppDataDictionary.FIX.4.1=../../share/quickfix/FIX41.xml
AppDataDictionary.FIX.4.2=../../share/quickfix/FIX42.xml
AppDataDictionary.FIX.4.3=../../share/quickfix/FIX43.xml
AppDataDictionary.FIX.4.4=../../share/quickfix/FIX44.xml
AppDataDictionary.FIX.5.0=../../share/quickfix/FIX50.xml
AppDataDictionary.FIX.5.0SP1=../../share/quickfix/FIX50SP1.xml
AppDataDictionary.FIX.5.0SP2=../../share/quickfix/FIX50SP2.xml
StartTime=00:00:00
EndTime=23:59:59
StartDay=sun
EndDay=sat

[SESSION]
TargetCompID=CRABEL-TEST
BeginString=FIXT.1.1
DefaultApplVerID=FIX.5.0SP2

Upvotes: 1

Related Questions