[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Your input is needed: Use regexp to match content
From: |
Ole Tange |
Subject: |
Your input is needed: Use regexp to match content |
Date: |
Mon, 30 Oct 2023 02:22:21 +0100 |
I am really happy about the {= =} construct (thanks Malcolm - it was a
brilliant idea).
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}'
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}
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
- Your input is needed: Use regexp to match content,
Ole Tange <=