fish: functions/gts: Add a helper to get column of interest from log files
This commit is contained in:
parent
c936941188
commit
800ec4ca64
1 changed files with 20 additions and 0 deletions
20
fish/.config/fish/functions/gts.fish
Normal file
20
fish/.config/fish/functions/gts.fish
Normal file
|
@ -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 <file_name> <search_pattern> <result_file>"
|
||||
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
|
Loading…
Reference in a new issue