From dd110ee036e7729f0abc90aa7824d970b23d2dbe Mon Sep 17 00:00:00 2001 From: Mason Rowe Date: Fri, 24 Mar 2023 23:23:48 -0400 Subject: [PATCH] replace all 'grep -P' instances (#59) --- yabs.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/yabs.sh b/yabs.sh index b5e8db7..d6fe32b 100644 --- a/yabs.sh +++ b/yabs.sh @@ -278,25 +278,25 @@ function ip_info() { return fi - local country=$(echo "$response" | grep -Po '"country": *\K"[^"]*"') + local country=$(echo "$response" | sed -e 's/[{}]/''/g' | awk -v RS=',"' -F: '/^country/ {print $2}' | head -1) country=${country//\"} - local region=$(echo "$response" | grep -Po '"regionName": *\K"[^"]*"') + local region=$(echo "$response" | sed -e 's/[{}]/''/g' | awk -v RS=',"' -F: '/^regionName/ {print $2}') region=${region//\"} - local region_code=$(echo "$response" | grep -Po '"region": *\K"[^"]*"') + local region_code=$(echo "$response" | sed -e 's/[{}]/''/g' | awk -v RS=',"' -F: '/^region/ {print $2}' | head -1) region_code=${region_code//\"} - local city=$(echo "$response" | grep -Po '"city": *\K"[^"]*"') + local city=$(echo "$response" | sed -e 's/[{}]/''/g' | awk -v RS=',"' -F: '/^city/ {print $2}') city=${city//\"} - local isp=$(echo "$response" | grep -Po '"isp": *\K"[^"]*"') + local isp=$(echo "$response" | sed -e 's/[{}]/''/g' | awk -v RS=',"' -F: '/^isp/ {print $2}') isp=${isp//\"} - local org=$(echo "$response" | grep -Po '"org": *\K"[^"]*"') + local org=$(echo "$response" | sed -e 's/[{}]/''/g' | awk -v RS=',"' -F: '/^org/ {print $2}') org=${org//\"} - local as=$(echo "$response" | grep -Po '"as": *\K"[^"]*"') + local as=$(echo "$response" | sed -e 's/[{}]/''/g' | awk -v RS=',"' -F: '/^as/ {print $2}') as=${as//\"} echo @@ -730,7 +730,7 @@ function iperf_test { done # Run a latency test via ping -c1 command -> will return "xx.x ms" - [[ ! -z $LOCAL_PING ]] && LATENCY_RUN="$(ping -c1 $URL 2>/dev/null | grep -Po 'time=.*' | sed s/'time='//)" + [[ ! -z $LOCAL_PING ]] && LATENCY_RUN="$(ping -c1 $URL 2>/dev/null | grep -o 'time=.*' | sed s/'time='//)" [[ -z $LATENCY_RUN ]] && LATENCY_RUN="--" # parse the resulting send and receive speed results