[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: Your input is needed: Use regexp to match content
From: |
Cook, Malcolm |
Subject: |
RE: Your input is needed: Use regexp to match content |
Date: |
Mon, 30 Oct 2023 17:51:49 +0000 |
Hi Ole,
> I am really happy about the {= =} construct (thanks Malcolm - it was a
> brilliant
> idea).
You're most welcome. I use it myself all the time 😉
> But it is a bit cumbersome to use that when a regexp would just match.
>
> echo 2023-10-29 |
> parallel echo 'Year={=s/(....)-..-../$1/=} Month={=s/....-(..)-../$1/=} Day
> of
> month={=s/....-..-(..)/$1/=}'
>
> In this case you could use --colsep:
>
> echo 2023-10-29 |
> parallel --colsep - echo 'Year={1} Month={2} Day of month={3}'
I don't yet see a motivating example that cannot make use of perl's named
capture groups.
Example:
echo 2023-10-29 | parallel echo
'{=s/(?<YYYY>....)-(?<MM>..)-(?<DD>..)/Year=$+{YYYY} Month=$+{MM} Day of
month=$+{DD}/=}'
Year=2023 Month=10 Day of month=29
> But when it gets more complex you cannot:
>
> echo 2023-10-29T23:59:59+01:00 |
> parallel echo ' \
> Y={=s/(....)-..-..T..:..:..[-+]..:../$1/=} \
> M={=s/....-(..)-..T..:..:..[-+]..:../$1/=} \
> D={=s/....-..-(..)T..:..:..[-+]..:../$1/=} \
> H={=s/....-..-..T(..):..:..[-+]..:../$1/=} \
> M={=s/....-..-..T..:(..):..[-+]..:../$1/=} \
> S={=s/....-..-..T..:..:(..)[-+]..:../$1/=} \
> Z={=s/....-..-..T..:..:..[-+](..:..)/$1/=}
> '
> or:
>
> echo 2023-10-29T23:59:59+01:00 |
> parallel --rpl '{D(.)} s/(....)-(..)-(..)T(..):(..):(..)[-+](..:..)/$$$1/' \
> echo Y={D1} M={D2} D={D3} H={D4} M={D5} S={D6} Z={D7}
>
> But wouldn't it be nice if you could simply match the line (THIS IS ONLY AN
> IDEA):
>
> echo 2023-10-29T23:59:59+01:00 |
> parallel --match '((....)-(..)-(..))T((..):(..):(..))[-+](..:..)' \
> echo YMD={1} Y={2} M={3} D={4} HMS={5} H={6} M={7} S={8} Z={9}
But you can do this already:
echo 2023-10-29T23:59:59+01:00 | parallel echo
'{=s/((....)-(..)-(..))T((..):(..):(..))[-+](..:..)/YMD=$1 Y=$2 M=$3 D=$4
HMS=$5 H=$6 M=$7 S=$8 Z=$9/=}'
YMD=2023-10-29 Y=2023 M=10 D=29 HMS=23:59:59 H=23 M=59 S=59 Z=01:00
YMMV,
~ Malcolm
>
> I am not sure how easy it is to implement, but let us assume it is doable.
> What should this do:
>
> echo 2023-10-29T23:59:59+01:00 |
> parallel --match '(....)-(..)-(..)T(..):(..):(..)[-+](..:..)' \
> echo {}
>
> Multiple input sources:
>
> parallel --match '(.)-(..)' echo {} {1}/{2}/{3}/{4} ::: A-BB C-DD ::: E-FF
> G-HH
>
> What happens if input data does not match:
>
> parallel --match '(.)-(..)' echo {} {1}/{2}/{3}/{4} ::: A-BB C-DD ::: -FF
> GG-HH
>
> Different formats for different input sources:
>
> parallel --match '(.)-(..)' --match '(..)-(.)' \
> echo {} {1}/{2}/{3}/{4} ::: A-BB C-DD ::: EE-F GG-H
>
> Can I access E-FF? (which used to be {2})
>
> parallel --match '(.)-(..)' \
> echo {2-orig?} {1}/{2}/{3}/{4} ::: A-BB C-DD ::: E-FF G-HH
>
> Or must I make a match group for the original {2}?
>
> parallel --match '((.)-(..))' \
> echo {4} {2}/{3}/{6}/{7} ::: A-BB C-DD ::: E-FF G-HH
>
> Is there an easy way to go from:
>
> parallel echo {2} {1} ::: A-BB C-DD ::: E-FF G-HH
>
> to this (where I have to calculate what number {4} would get):
>
> parallel --match '((.)-(..))' \
> echo {4} {1} {3} ::: A-BB C-DD ::: E-FF G-HH
>
> Maybe matched vars should not be called {4} but {m4}; so {2} can keep its
> meaning?
>
>
> /Ole