Skip to content

Instantly share code, notes, and snippets.

@afriza
Last active November 23, 2022 03:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save afriza/01c6d0f77c8cad8ae5abae1a6c3847dc to your computer and use it in GitHub Desktop.
Save afriza/01c6d0f77c8cad8ae5abae1a6c3847dc to your computer and use it in GitHub Desktop.
GNU sed to remove color
#!/bin/sh
sed=sed
if [ `uname` == "Darwin" ]; then
sed=`command -v gsed`
ret=$?
if [ "$ret" -ne 0 ]; then
echo 'GNU sed needs to be installed. Install with: brew install gnu-sed'
exit $ret
fi
fi
# Ref: https://stackoverflow.com/questions/17998978/removing-colors-from-output#comment125240462_18000433
$sed -r "s/\x1B\[([0-9]{1,3}(;[0-9]{1,3})*)?[mGK]//g" "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment