Created
July 5, 2011 18:10
-
-
Save 13k/1065448 to your computer and use it in GitHub Desktop.
bash utils: stripping
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
# strip whitespace | |
strip() { local s="${1/%*([[:space:]])}"; echo "${s/#*([[:space:]])}"; } | |
# strip non-printing escape sequences (\[ ... \]) from string | |
strip_np() { | |
local c=`echo -e "\x06"` | |
local tmp="${1//@(\\\[|\\\])/$c}" | |
echo "${tmp//${c}*([^${c}])${c}}" | |
} | |
# strip colors (\e[ii;jjm) from string | |
strip_cl() { echo "${1//\\e\[+([[:digit:]]);+([[:digit:]])m/}"; } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment