Created
February 21, 2019 03:29
-
-
Save msroz/89ded2a2e4da1263acdf87b002d53363 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 | |
Author
msroz
commented
May 16, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment