Last active
November 23, 2022 03:09
-
-
Save afriza/01c6d0f77c8cad8ae5abae1a6c3847dc to your computer and use it in GitHub Desktop.
GNU sed to remove color
This file contains 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/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