Reputation: 1821
I want to match the following line with the regex in sed:
db=connect_str=DBI:SQLAnywhere:ENG=ABC1_hostname12;DBN=ABC12;UID=USERID;PWD=passwd123;LINKS=tcpip{host=10.11.12.13:1234}
The regex I am using is:
sed -n '/ABC1_.+;/p' Config/db_conn.cfg
but this does not work. On the other hand, it works if I use:
sed -n '/ABC1_.*;/p' Config/db_conn.cfg
Can someone please explain why it's not working? Also is there another way to match it?
Upvotes: 0
Views: 1535
Reputation: 56905
It's because sed is basic regex by default, which needs +
to be escaped or else it represents a literal +
instead of a regex +
:
sed -n '/ABC1_.\+;/p' Config/db_conn.cfg
To use regex you're familiar with try sed -r -n
(extended regex) and then you can do:
sed -r -n '/ABC1_.+;/p' Config/db_conn.cfg
Upvotes: 3