Skip to main content

How to use matching group in sed replacement

·22 words·1 min

With one capture group
#

sed -i 's/^Title\: \(.*\)$/title: "\1"/g' *.md

With more capture groups
#

sed -i 's|^Date: \([[:digit:]]\{4\}\)/\([[:digit:]]\{2\}\)/|date: \1-\2-|g' *.md