regex - Printing a matched regexp with sed -
so i'm trying match regexp string in middle of , print out string. syntax sort of this...
sed -n 's/<title>.*</title>/"what put here"/p' input.file and want print out whatever .* typed "what put here". i'm not comfortable sed @ point simple answer , i'm having trouble finding 1 in of other questions. in advance!
capture pattern want extract within \(...\), , can refer \1 in replacement string:
sed -n 's/<title>\(.*\)</title>/\1/p' input.file you can have multiple \(...\) expressions, , refer them \1, \2, \3, , on.
if have gnu version of sed, or gsed, simplify bit:
sed -rn 's/<title>(.*)</title>/\1/p' input.file with -r flag, sed can use "extended regular expressions", practically let's write (...) instead of \(...\), + instead of \+, , other goodies.
Comments
Post a Comment