Last active
February 3, 2022 20:48
-
-
Save dcode/b49b6728d245a3a3f151 to your computer and use it in GitHub Desktop.
Will truncate each field to a maximum value (set via $1) and colorize output. Useful to tabulate data.
Also included the original colorize that doesn't truncate.
This file contains hidden or 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 | |
| cat - | sed 's/^#[a-z]*s[^a-z]//' | gawk -vOFS='\t' -vT_LEN="$T_LEN" 'BEGIN {FS="\t" }; {for(i=1;i<=NF;i++) { printf("\x1b[%sm%s\t\x1b[0m",(i%7)+31,$i) } ;print ""}' |
This file contains hidden or 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
| cat x509.log | head -200 | trunc_and_color 30 | column -s' ' -t -x | less -SR |
This file contains hidden or 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 | |
| T_LEN=$1 | |
| cat - | sed 's/^#[a-z]*s[^a-z]//' | gawk -vOFS='\t' -vT_LEN="$T_LEN" 'BEGIN {FS="\t" }; {for(i=1;i<=NF;i++) { if(length($i)>T_LEN) { $i=substr($i,1,T_LEN); } printf("\x1b[%sm%s\t\x1b[0m",(i%7)+31,$i) } ;print ""}' |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example screenshot:
