Skip to content

Instantly share code, notes, and snippets.

@davidallsopp
Last active October 2, 2015 14:28
Show Gist options
  • Save davidallsopp/5a5f199a0e4a843d7982 to your computer and use it in GitHub Desktop.
Save davidallsopp/5a5f199a0e4a843d7982 to your computer and use it in GitHub Desktop.
Colouring a text file to highlight spaces, tabs, etc. See also cat -A
#!/bin/bash
RED=`echo -e '\033[41m\033[37m'`
BLUE=`echo -e '\033[44m\033[37m'`
NORMAL=`echo -e '\033[0m'`
cat "$1" | sed -e s/\ /${BLUE}\ ${NORMAL}/g | sed -e s/$'\t'/${RED}\ \ \ \ ${NORMAL}/g
@davidallsopp
Copy link
Author

Unfortunately doesn't play well with "less" (shows control chars) or "more" (shows blue spaces wrapping round entire lines, in some cases)

@davidallsopp
Copy link
Author

Solved: pipe the output to "less -R", which preserves the colour escape sequences

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