Skip to content

Instantly share code, notes, and snippets.

@noqqe
Created April 16, 2011 14:45
Show Gist options
  • Select an option

  • Save noqqe/923159 to your computer and use it in GitHub Desktop.

Select an option

Save noqqe/923159 to your computer and use it in GitHub Desktop.
Replace Unix tools with bash interna
diff --git a/statistical b/statistical
index 50f443c..17423b3 100755
--- a/statistical
+++ b/statistical
@@ -20,11 +20,11 @@ fi
for data in $SUM; do
# Getting informations from parameters
- KEY=$(echo $data | awk -F: '{printf $1}')
- VALUE=$(echo $data | awk -F: '{print $2}')
-
+ KEY=${data%%:*}
+ VALUE=${data##*:}
+
# Fishing errors from wrong usage
- if $(echo $VALUE | grep -q -v -P '^\d{1,}$'); then
+ if [[ ! $VALUE =~ ^[[:digit:]]+$ ]]; then
echo "ERROR: Do not use characters as value! Key:$KEY"
exit 1
fi
@@ -71,9 +71,8 @@ done
# Start graphing
for data in $SUM; do
- KEY=$(echo $data | awk -F: '{printf $1}')
- REAL_KEY=$KEY
- VALUE=$(echo $data | awk -F: '{print $2}')
+ KEY=${data%%:*}
+ VALUE=${data##*:}
REAL_VALUE="$VALUE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment