Created
January 28, 2025 21:53
-
-
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`.
This file contains hidden or 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
# 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