Skip to content

Instantly share code, notes, and snippets.

# Extract specific tag content (TAG given via env var)
(define TAG shell variable)
TAG=hoge
(including the taret tag name)
A) perl -0777 -ne "print qq{\$&\n} if /<${TAG}\b[^>]*>.*?<\\/${TAG}>/sg" input.xml
or
B) perl -0777 -ne 'print "$&\n" if /<'"$TAG"'\b[^>]*>.*?<\/'"$TAG"'>/sg' input.xml
or