Iurii
Iurii

Reputation: 1795

Sed print digits from string

Have next configuration file:

[DEFAULT]
SenderCompID=PB
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

I want to print value of SocketAcceptPort tag by using sed, in my case it's 4444. I used this regexp but no luck: sed 's/SocketAcceptPort=[0-9]+//g' file.cfg Thanks in advance.

Upvotes: 0

Views: 90

Answers (3)

Avinash Raj
Avinash Raj

Reputation: 174854

Through sed,

$ sed -n '/^SocketAcceptPort/s/.*=//p' file
4444

It searches for the line which starts with SocketAcceptPort, if it found any then it remove all the characters upto the = symbol. Finally the remaining characters got printed. In our case it's 4444

Upvotes: 2

sat
sat

Reputation: 14979

Another sed,

sed -n 's/^SocketAcceptPort=\([0-9]\+\).*/\1/p' yourfile

If you have -E option in sed,

sed -En 's/^SocketAcceptPort=([0-9]+).*/\1/p' yourfile

Upvotes: 0

Jotne
Jotne

Reputation: 41460

You can do it with awk if you like to try:

awk -F= '/SocketAcceptPort/ {print $2}' file 
4444

Upvotes: 0

Related Questions