From caf75bc4baef1fefaae9adc5beed64660aabcdb5 Mon Sep 17 00:00:00 2001 From: Marc Hiatt Date: Fri, 13 Oct 2023 12:30:51 +0200 Subject: [PATCH] No need for grep, just use sed's addressing capability --- worddiv | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/worddiv b/worddiv index 7f9ea99..99ed7fd 100755 --- a/worddiv +++ b/worddiv @@ -57,21 +57,25 @@ until test "$expression" = "q" ; do sed "s/expression/$expression/g" > $tmpdir/$secondary_filename # american - babel_output=$(cd $tmpdir && latex -draftmode $tmpdir/$expression_filename | - grep "\\[\\] .OT1" | sed -E "s/.* ([-a-z]*)$/\1/") + babel_output=$(cd $tmpdir && latex -draftmode $tmpdir/$expression_filename | + # print nothing (sed -n) except the line that matches + # the regexp "/] .OT1/", but only after replacing the + # whole of that line with part of itself, namely last + # glob of letters and hyphens that comes after a space: + sed -nE "/] .OT1/s/.* ([-a-zA-Z]*)$/\1/p") # british babel_output_secondary=$(cd $tmpdir && latex -draftmode $tmpdir/$secondary_filename | - grep "\\[\\] .OT1" | sed -E "s/.* ([-a-z]*)$/\1/") + sed -nE "/] .OT1/s/.* ([-a-zA-Z]*)$/\1/p") ## tex+showhyphens tex_output=$(echo "\showhyphens{$expression}" | tex -output-directory "$tmpdir" | - sed -nE --posix "/tenrm/s/.* ([-a-z])/\1/p") + sed -nE --posix "/tenrm/s/.* ([-a-zA-Z])/\1/p") ## run comparisons ... # - # test these by querying the words 'multifacted', 'important', and 'rearranged' + # test these by querying the words 'multifacted', 'important', 'rearranged', and 'Switzerland' # # babel AE vs plain TeX if test "$babel_output" = "$tex_output" ; then