Skip to content

Instantly share code, notes, and snippets.

@13k
Created July 5, 2011 18:10
Show Gist options
  • Save 13k/1065448 to your computer and use it in GitHub Desktop.
Save 13k/1065448 to your computer and use it in GitHub Desktop.
bash utils: stripping
# 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