diff options
-rwxr-xr-x | anykernel.sh | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/anykernel.sh b/anykernel.sh index 5c8d6d1..8c90a4e 100755 --- a/anykernel.sh +++ b/anykernel.sh @@ -115,7 +115,7 @@ replace_string() { # replace_section <file> <begin search string> <end search string> <replacement string> replace_section() { - line=`grep -n "$2" $1 | cut -d: -f1`; + line=`grep -n "$2" $1 | head -n1 | cut -d: -f1`; sed -i "/${2//\//\\/}/,/${3//\//\\/}/d" $1; sed -i "${line}s;^;${4}\n;" $1; } @@ -132,7 +132,7 @@ insert_line() { before) offset=0;; after) offset=1;; esac; - line=$((`grep -n "$4" $1 | cut -d: -f1` + offset)); + line=$((`grep -n "$4" $1 | head -n1 | cut -d: -f1` + offset)); sed -i "${line}s;^;${5}\n;" $1; fi; } @@ -140,7 +140,7 @@ insert_line() { # replace_line <file> <line replace string> <replacement line> replace_line() { if [ ! -z "$(grep "$2" $1)" ]; then - line=`grep -n "$2" $1 | cut -d: -f1`; + line=`grep -n "$2" $1 | head -n1 | cut -d: -f1`; sed -i "${line}s;.*;${3};" $1; fi; } @@ -148,7 +148,7 @@ replace_line() { # remove_line <file> <line match string> remove_line() { if [ ! -z "$(grep "$2" $1)" ]; then - line=`grep -n "$2" $1 | cut -d: -f1`; + line=`grep -n "$2" $1 | head -n1 | cut -d: -f1`; sed -i "${line}d" $1; fi; } @@ -167,7 +167,7 @@ insert_file() { before) offset=0;; after) offset=1;; esac; - line=$((`grep -n "$4" $1 | cut -d: -f1` + offset)); + line=$((`grep -n "$4" $1 | head -n1 | cut -d: -f1` + offset)); sed -i "${line}s;^;\n;" $1; sed -i "$((line - 1))r $patch/$5" $1; fi; |