Skip to content

Instantly share code, notes, and snippets.

@dbowling
Created January 28, 2025 21:53
Show Gist options
  • Save dbowling/9b7ef6169ddf368016b5f571fcab6a77 to your computer and use it in GitHub Desktop.
Save dbowling/9b7ef6169ddf368016b5f571fcab6a77 to your computer and use it in GitHub Desktop.
Add this to your `.zshrc` file to give you access to `ltrim` and `rtrim`.
# usage: cat [file] | rtrim | ltrim | sort | uniq
# Right trim: Removes trailing whitespace
rtrim() {
while IFS= read -r line; do
echo "${line%"${line##*[![:space:]]}"}"
done
}
# Left trim: Removes leading whitespace
ltrim() {
while IFS= read -r line; do
echo "${line#"${line%%[![:space:]]*}"}"
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment