I have many lines like the following being returned from a bash command, with different sourceNodeIds
of varying digit lengths:
<NodeAssociation sourceNodeId="33654" [...] sourceNodeEntity="Issue" />
I'd like to pipe it to sed or awk and just return the number nnnn from sourceNodeId="nnnn"
something like:
cat blah | sed 's/.+?sourceNodeId="\(\d+\)".+/\1/'
but this isn't working. I'm on a Mac if that makes any difference (I think the version of sed may be different). I know Perl regexes, but I think sed is expecting a different kind.
Thanks!!!
sed
doesn't know about\d
and non-greedy matches. You don't need to usecat
. This should work:Some
sed
versions are picky about wanting a-e
(it will work even if it's not required):If your
sed
supports-r
you can skip the escaping:Also, works: