Skip to main content
1 of 2
HappyFace
  • 1.7k
  • 14
  • 29
trimpy () {
    python3 -c 'import sys
for line in sys.stdin: print(line.strip())'
}
trimsed () {
gsed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//'
}
# example usage
echo " hi " | trimpy

Bonus: replace str.strip([chars]) with arbitrary characters to trim or use .lstrip() or .rstrip() as needed.

(This is just a remix of other answers here.)

HappyFace
  • 1.7k
  • 14
  • 29