I know it's possible with regex, but given how frequently that parsing logic is needed, and the difficulty of getting sed right, I think a "tb" tool would be very helpful.
I know it's possible with regex, but given how frequently that parsing logic is needed, and the difficulty of getting sed right, I think a "tb" tool would be very helpful.
Reading a value from "<td>2017-01-09 <b>08:30</b></td>" is harder than it should be.
cut needs single-character delimiters, so only splitting on "<" or ">" won't work.
sed trips up on the "/", ":", and "-" without proper escaping.
This is before even mentioning Unicode. High-level scripting languages handle all of these just fine. I'd much rather have a standard tool and library for this purpose though.
$ echo '<td>2017-01-09 <b>08:30</b></td>' | awk -F'[<>]' '{print $5}'
This will give you '08:30'. Unicode seems to be also supported: $ echo 'λf. (λx. f (x x)) (λx. f (x x))' | awk -F'[λ.]' '{print $4}'
This prints 'x'. For clarity some other matches: $1: ''
$2: 'f'
$3: ' ('
$4: 'x'
...I'm just suggesting easier syntax, and a custom tool. Like dd is for disk copying, instead of cp/gzip/etc. A simple tool that will just work.
This is the syntax I'm going for: textBetween("<td>", "</td>") | replace ("<b>", "") | replace ("</b>", "")
Maybe with some magic strings,
e.g. textBetween(":", "end")
Your replace part is already covered by sed (although I agree with you that the escaping can be awkward).
cat dates | python -c 'import sys; for line in sys.stdin: print(line.split("<td>"))'
Or PHP php -r 'foreach (explode("\n", file_get_contents("dates")) as $line) { print_r(explode("<td>", $line)); }'
Or with Perl or Ruby or whatever floats your boat.While writing this I did think of something though, depending on what you're actually trying to do it might work:
cat dates | tr "<>" " " | awk '{print $yourColumnOfInterest}'Back to the article. dd is not a disk writing tool. Everything on UNIX is a disk writing tool. dd has one job, and does it right.
Again, I propose a single-purpose text delimiter cutting program. It doesn't need to be a whole scripting language, e.g. awk, perl, python, etc. Just get the text between two strings, and have sensible syntax.