79665196

Date: 2025-06-13 17:24:00
Score: 1
Natty:
Report link
echo 'Subject : "O=This is a test,CN=abc.def.com,L=North,ST=Arizona,C=CA"' |sed -r 's/.*CN=([^,]*)[,].*/\1/'
abc.def.com

linux bash sed: '-r' allows to use '()' without escaping search pattern: any char and "CN=" : .*CN= ( any char but not ',': [^,]* ) # remember/save this part in var 1 ',' and any char: [,].* replace with saved buffer/variable: \1

Cutting out strings is a very common task and can be done in various ways as shown above already: so I am also always looking for new ways and always taking into account the available tools and patterns to have an easy, fast and precise solution.

Happy cutting!

brgds

stefan

Reasons:
  • Contains signature (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: Stefan