From e625abc2855937f0205b69e390dd992f90bed692 Mon Sep 17 00:00:00 2001 From: Jonathan Hodgson Date: Thu, 25 Mar 2021 21:22:48 +0000 Subject: [PATCH] Adds early version of lookup contact script --- bin/.bin/lookup-contact | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100755 bin/.bin/lookup-contact diff --git a/bin/.bin/lookup-contact b/bin/.bin/lookup-contact new file mode 100755 index 00000000..2ed0fb1b --- /dev/null +++ b/bin/.bin/lookup-contact @@ -0,0 +1,18 @@ +#!/usr/bin/env bash + +addressbook="$HOME/.abook/addressbook" + +cat "$addressbook" | + grep -E '(\[[0-9]+\]|^$|name|phone|mobile)' | + awk -v RS="\n\n" -v ORS="\n" '{gsub("\n","\t",$0); print $0}' | + grep -E "(phone|mobile)" | while read -r line; do + name="$(echo "$line" | cut -d ' ' -f 2 | cut -d '=' -f 2)" + echo "$line" | tr '\t' '\n' | + grep -E '(phone|mobile)' | while read -r numLine; do + num="$(echo "$numLine" | cut -d '=' -f 2 | tr -d ' ' | sed 's/+44(0)/+44/')" + numType="$(echo "$numLine" | cut -d '=' -f 1)" + echo -e "$name\t$num\t$numType" + done + + echo "" + done