summaryrefslogtreecommitdiff
path: root/anykernel.sh
diff options
context:
space:
mode:
authorosm0sis <osm0sis@outlook.com>2016-08-16 02:22:34 -0300
committerosm0sis <osm0sis@outlook.com>2016-08-16 02:22:34 -0300
commit3557b290f207684b3b20d5e915aee295c986a714 (patch)
tree164becdb5b4588ec9f44de02d5070dee80b5aa6b /anykernel.sh
parentd0a43839fea4b5ef8e4b6d0278c87790eb3a1c0d (diff)
AK2: explicitly only take the first match in functions using line matching
Diffstat (limited to 'anykernel.sh')
-rwxr-xr-xanykernel.sh10
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;