Skip to content

Instantly share code, notes, and snippets.

@msroz
Created February 21, 2019 03:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save msroz/89ded2a2e4da1263acdf87b002d53363 to your computer and use it in GitHub Desktop.
Save msroz/89ded2a2e4da1263acdf87b002d53363 to your computer and use it in GitHub Desktop.
#!/bin/bash
# written by msroz
#{{shelldoc}}
# Name:
# ltsvkey.sh - print ltsv key with line number
#
# Usage:
# ./ltsvkey.sh < ltsv.file
# head ltsv.file | ./ltsvkey.sh
#
# Remarks:
#
# Dependencies:
#
#{{shelldoc}}
set -euC
count=1
first_line=$(cat - | head -n 1)
printf "%-3s\t%-30s\t%-30s\n" 'number' 'key' 'example'
echo '------------------------------------------------'
IFS=$(echo -e '\t') # Do not split space
for field in $first_line; do
key=$(echo $field | cut -d ':' -f 1)
value=$(echo $field | cut -d ':' -f 2-)
printf "%-3s\t%-30s\t%-30s\n" $count $key $value
count=$(expr $count + 1)
done
IFS=$' \t\n'
exit 0
@msroz
Copy link
Author

msroz commented May 16, 2019

tail -n 1 /path/to/ltsv.log | bash <(curl -s https://gist.githubusercontent.com/msroz/89ded2a2e4da1263acdf87b002d53363/raw/6693b1aa98450d3c2d59fdfdfecf38ff9a6b4ff8/ltsvkey.sh)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment