From 800ec4ca6479e1bff44ccaca27874d64dfab34ba Mon Sep 17 00:00:00 2001 From: Sanchayan Maity Date: Sat, 16 Apr 2022 13:34:41 +0530 Subject: [PATCH] fish: functions/gts: Add a helper to get column of interest from log files --- fish/.config/fish/functions/gts.fish | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 fish/.config/fish/functions/gts.fish diff --git a/fish/.config/fish/functions/gts.fish b/fish/.config/fish/functions/gts.fish new file mode 100644 index 0000000..cf03019 --- /dev/null +++ b/fish/.config/fish/functions/gts.fish @@ -0,0 +1,20 @@ +# Naming this gts as we primarily want to use this for getting timestamp +# columns from GStreamer logs but is general purpose to be used for other +# things. +function gts --description "Get column next to column matching a pattern" -a file pattern result_file + if test (count $argv) -lt 3 + echo "Usage: gts " + echo "Eg: gts gstreamer-ts.log pts /tmp/result.csv" + else + # Found the trick to use passed argument as an awk pattern below + # https://stackoverflow.com/questions/39366910/how-to-escape-fish-shell-variable-to-use-as-awk-pattern + # The actual incantation is a modification from the solution here + # https://stackoverflow.com/questions/67608136/print-column-next-to-the-column-matching-a-pattern + if test -e $result_file + echo "Result file $result_file exists, removing..." + rm $result_file + end + awk -v pat="$pattern" 'BEGIN{FS=OFS=" "} {for(i=1;i<=NF;i++){if($i==pat){print $(i+1);next}}}' $file >>$result_file + nvim $result_file + end +end