Skip to content

Instantly share code, notes, and snippets.

@dcode
Last active February 3, 2022 20:48
Show Gist options
  • Select an option

  • Save dcode/b49b6728d245a3a3f151 to your computer and use it in GitHub Desktop.

Select an option

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.
#!/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 ""}'
cat x509.log | head -200 | trunc_and_color 30 | column -s' ' -t -x | less -SR
#!/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 ""}'
@dcode

dcode commented Nov 11, 2015

Copy link
Copy Markdown
Author

Example screenshot:
1____sync_jeff-pcap_hq_dump__column__and_peak_script_____main_theme_dark_16-9_key

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