Quantcast
Channel: Active questions tagged jq - Stack Overflow
Viewing all articles
Browse latest Browse all 524

Using backreference as replacement string in JQ

$
0
0

Assuming I want to extract the time part of a date/time string on the shell I can do something like:

echo "2021-06-10T10:42:30.016+0200" | sed 's|.*T\(.*\)\..*|\1|g'

This returns

10:42:30

How can I achieve the same with jq and sub()?I'm missing the right syntax. I was not able to find any good examples. E.g. I've been trying:

jq '<myid> | sub(".*T(.*)\\..*"; "\1")'jq '<myid> | sub(".*T(.*)\\..*"; "$1")'jq '<myid> | sub(".*T\\(.*\\)\\..*"; "\1")'

But none of this returns back what I want?


Viewing all articles
Browse latest Browse all 524

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>