From adc21ed2c37503b540b5fbc18af0ca46bdf24cf8 Mon Sep 17 00:00:00 2001 From: osm0sis Date: Tue, 4 Jul 2017 14:24:12 -0300 Subject: [PATCH] AK2: allow next blank line (" ") for replace_section and remove_section - sometimes it's difficult to anchor to specific end lines due to variations across ROMs, so allow the end line to be blank " " - note this will also remove the trailing blank line so for replacements a trailing \n should be added to maintain spacing; this should be pretty intuitive since you are including the blank line as the end line search --- tools/ak2-core.sh | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tools/ak2-core.sh b/tools/ak2-core.sh index ce106a5..a099b6f 100755 --- a/tools/ak2-core.sh +++ b/tools/ak2-core.sh @@ -254,7 +254,11 @@ replace_section() { begin=`grep -n "$2" $1 | head -n1 | cut -d: -f1`; for end in `grep -n "$3" $1 | cut -d: -f1`; do if [ "$begin" -lt "$end" ]; then - sed -i "/${2//\//\\/}/,/${3//\//\\/}/d" $1; + if [ "$3" == " " ]; then + sed -i "/${2//\//\\/}/,/^\s*$/d" $1; + else + sed -i "/${2//\//\\/}/,/${3//\//\\/}/d" $1; + fi; sed -i "${begin}s;^;${4}\n;" $1; break; fi; @@ -266,7 +270,11 @@ remove_section() { begin=`grep -n "$2" $1 | head -n1 | cut -d: -f1`; for end in `grep -n "$3" $1 | cut -d: -f1`; do if [ "$begin" -lt "$end" ]; then - sed -i "/${2//\//\\/}/,/${3//\//\\/}/d" $1; + if [ "$3" == " " ]; then + sed -i "/${2//\//\\/}/,/^\s*$/d" $1; + else + sed -i "/${2//\//\\/}/,/${3//\//\\/}/d" $1; + fi; break; fi; done;