From: Paul Hänsch Date: Sat, 23 Jan 2021 13:06:42 +0000 (+0100) Subject: portable sed usage X-Git-Url: https://git.plutz.net/?a=commitdiff_plain;h=a6e3da877a73be739ac96b12d9cde2190b24a423;p=confetti portable sed usage --- diff --git a/cards/filter_card.sh b/cards/filter_card.sh index 183278f..e7d1114 100755 --- a/cards/filter_card.sh +++ b/cards/filter_card.sh @@ -30,7 +30,7 @@ filter="$( else printf '^%s:%s' "$filter_type" "$filter_text" fi - done | sed -r \ + done | sed -E \ 's;\|+;\|;g; s;\^+;\^;g; s;:\|;:;g; :X; s;\^[^:]*:\^;\^;g; /\^[^:]*:\^/bX; s;^\^;;; s;\^[^:]*:$;;;' diff --git a/cards/list.sh b/cards/list.sh index 421ff3a..ab67fbd 100755 --- a/cards/list.sh +++ b/cards/list.sh @@ -149,7 +149,7 @@ filter_cards(){ printf '%s\n' "$cardfile" cat "$cardfile" done \ - | sed -En ':X; /\nEND:VCARD\r?$/!{ N; bX; }; h; s;\n.*$;;; x; s;^[^\n]+\n;;; + | sed -nE ':X; /\nEND:VCARD\r?$/!{ N; bX; }; h; s;\n.*$;;; x; s;^[^\n]+\n;;; '"$upcase""$fex" } diff --git a/categories/edit_categories.sh b/categories/edit_categories.sh index fe97790..232499b 100755 --- a/categories/edit_categories.sh +++ b/categories/edit_categories.sh @@ -25,7 +25,7 @@ newcat="$(POST newcat)" if [ "$(POST add)" = "add" ]; then printf %s\\n "$newcat" >>"$catfile" elif [ "$remove" ]; then - sed -Ei '/^'"${remove}"'$/d' "$catfile" + sed -E -i '/^'"${remove}"'$/d' "$catfile" fi REDIRECT "/categories/" diff --git a/categories/update_categories.sh b/categories/update_categories.sh index 944c3d2..108c5d5 100755 --- a/categories/update_categories.sh +++ b/categories/update_categories.sh @@ -30,7 +30,7 @@ for card in "${_DATA}"/vcard/*.vcf; do n=1; while cardcats="${cardcats}${cardcats:+,}$(pdi_value "$vcf" CATEGORIES $n)"; do n=$((n+1)); done if [ "${postcats}" != "${cardcats}" ] && LOCK "$card"; then - sed -ri ' + sed -E -i ' /^CATEGORIES[;:]/d /^END;?:VCARD *\r?$/iCATEGORIES:'"${postcats%,}"'\r ' "${card}" diff --git a/courses/list.sh b/courses/list.sh index d8d3bf7..e9ae7bc 100755 --- a/courses/list.sh +++ b/courses/list.sh @@ -81,7 +81,7 @@ course_mail() { cat "${_DATA}/vcard/${card}" done \ | pdi_load - \ - | sed -rn 's;^EMAIL(\;[^:]*)*:(.+)\r?$;\2,;p' \ + | sed -nE 's;^EMAIL(\;[^:]*)*:(.+)\r?$;\2,;p' \ | tr -d \\n \ | unescape } diff --git a/courses/update_course.sh b/courses/update_course.sh index d76e43a..ea03a72 100755 --- a/courses/update_course.sh +++ b/courses/update_course.sh @@ -108,7 +108,7 @@ case "$(POST action)" in REDIRECT "/courses/?e=${course}" ;; addfield\ [A-Z]*) - newfield="$(POST action |sed -rn '1s;^addfield ([A-Z][A-Z0-9-]*)$;\1;p')" + newfield="$(POST action |sed -nE '1s;^addfield ([A-Z][A-Z0-9-]*)$;\1;p')" ics="$(pdi_update_value "$ics" "$newfield" $(( $(pdi_count "$ics" "$newfield") + 1 )) '')" printf '%s' "$ics" |grep -vx '' >"$tempfile" REDIRECT "/courses/?e=${course}" @@ -118,7 +118,7 @@ case "$(POST action)" in grep -F "${course} " "$attfile" |while read junk card; do touch "$_DATA/vcard/${card}" done - sed -i -r "/^${course} .+\$/d" "$attfile" + sed -E -i "/^${course} .+\$/d" "$attfile" seq 1 $(POST_COUNT attendance) |while read n; do printf '%s %s\n' "$course" "$(POST attendance $n)" done >>"$attfile" diff --git a/courses/widgets.sh b/courses/widgets.sh index 6123aa0..5b5288c 100755 --- a/courses/widgets.sh +++ b/courses/widgets.sh @@ -35,7 +35,7 @@ w_sort_courses(){ } cal_date(){ - { [ $# -eq 0 ] && cat || printf %s "$*"; } |sed -rnE ' + { [ $# -eq 0 ] && cat || printf %s "$*"; } |sed -nE ' 2q s/^([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2})([0-9]{2})([0-9]{2})Z$/\1-\2-\3 \4:\5:\6 UTC/p;t s/^TZID=(.+)\:([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2})([0-9]{2})([0-9]{2})$/TZ="\1" \2-\3-\4 \5:\6:\7/p;t @@ -160,10 +160,10 @@ edit_item(){ local dstart="${dtstart##*-}"; dstart="${dstart%% *}" local rrule="$(pdi_value "$course" RRULE)" - local rr_int="$(printf %s "$rrule" |sed -rn 's;^(.*\;[ ]*)?INTERVAL=([0-9]+)(\;.*)?$;\2;p')" - local rr_count="$(printf %s "$rrule" |sed -rn 's;^(.*\;[ ]*)?COUNT=([0-9]+)(\;.*)?$;\2;p')" - local rr_freq="$(printf %s "$rrule" |sed -rn 's;^(.*\;[ ]*)?FREQ=(DAILY|WEEKLY|MONTHLY|YEARLY)(\;.*)?$;\2;p')" - local rr_until="$(printf %s "$rrule" |sed -rn 's;^(.*\;[ ]*)?UNTIL=([0-9]{8}T[0-9]{6}Z)(\;.*)?$;\2;p')" + local rr_int="$(printf %s "$rrule" |sed -nE 's;^(.*\;[ ]*)?INTERVAL=([0-9]+)(\;.*)?$;\2;p')" + local rr_count="$(printf %s "$rrule" |sed -nE 's;^(.*\;[ ]*)?COUNT=([0-9]+)(\;.*)?$;\2;p')" + local rr_freq="$(printf %s "$rrule" |sed -nE 's;^(.*\;[ ]*)?FREQ=(DAILY|WEEKLY|MONTHLY|YEARLY)(\;.*)?$;\2;p')" + local rr_until="$(printf %s "$rrule" |sed -nE 's;^(.*\;[ ]*)?UNTIL=([0-9]{8}T[0-9]{6}Z)(\;.*)?$;\2;p')" local rr_uyear="${rr_until%????T??????Z}" local rr_umonth=${rr_until#????}; rr_umonth="${rr_umonth%??T??????Z}" local rr_uday=${rr_until#??????}; rr_uday="${rr_uday%T??????Z}"