Skip to content

Instantly share code, notes, and snippets.

@chabad360
Last active April 9, 2019 06:25
Show Gist options
  • Save chabad360/2764a5451206b3d514de26162ba9ee37 to your computer and use it in GitHub Desktop.
Save chabad360/2764a5451206b3d514de26162ba9ee37 to your computer and use it in GitHub Desktop.
Prints a file in a easy to find format, useful for logging config files (Uses colors!)
#!/bin/bash
# Function usage 'output ./test.txt "Test File"'
function output () {
TITLE=$2 NAME=${3:-$(echo "$1" | grep -o '\([^\/\\]\+\.\w\+\)$')} awk 'BEGIN{print "\033[1;36m" ENVIRON["TITLE"] \
":\n\033[0;31m" ENVIRON["NAME"] "\t|\033[1;31m ------------------------------------------------------------------------\033[0m"} \
{print "\033[0;31m" ENVIRON["NAME"] "\t| \033[0m" $0} END{print "\033[0;31m" \
ENVIRON["NAME"] "\t|\033[1;31m ------------------------------------------------------------------------\033[0m\n"}' $1
}
echo -e "test\n\
test1\n\
test2" > test.txt
output ./test.txt "Test File"
# Output:
# Test File:
# test.txt | ------------------------------------------------------------------------
# test.txt | test
# test.txt | test1
# test.txt | test2
# test.txt | ------------------------------------------------------------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment