Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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