trim is a small tool to strip characters from the beginning and/or end of each input line.
- Strip characters from both sides of a line.
- Strip characters only from the beginning (
--left). - Strip characters only from the end (
--right). - Supports custom characters.
- Supports escaped characters such as
\n,\t, etc. - Works with standard input and output, making it suitable for pipelines.
Download latest version from Release page and extract.
- Clone this repository:
git clone https://github.com/Hoang-Long2012/trim.git
- Run:
cd src
python trim.py
- Install PyInstaller:
pip install pyinstaller
- Build:
pyinstaller --onefile --name trim trim.py
trim [OPTIONS] [CHARS...]
trim reads text from standard input, processes each line, and writes the result to standard output.
- Remove spaces from both ends:
echo " Hello World " | trim
Output:
Hello World
- Remove custom characters:
echo "xxxHello Worldxxx" | trim x
Output:
Hello World
- Remove only the right side:
echo "Hello Worldxxx" | trim -r x
Output:
Hello World
- Remove only the left side:
echo "xxxHello World" | trim -l x
Output:
Hello World
| Option | Description |
|---|---|
-v, --version |
Show program version. |
-h, --help |
Show help message. |
-r, --right |
Strip characters only from the end of the line. |
-l, --left |
Strip characters only from the beginning of the line. |
-w, --whitespace |
Strip junk characters even when a custom character set has been specified. |
-e, --end |
Line ending of output. |
CHARS |
Characters to strip. |
The CHARS argument specifies the characters that should be removed.
CHARS is treated as a character set, not a string. For example:
trim abc
removes any combination of a, b, and c characters from the beginning and end of each line.
trim supports escape sequences in the character argument.
trim "\\t"
Remove tab characters.
trim "\\n"
Remove newline characters.
This project is licensed under the MIT License.
Copyright (c) 2026 Hoàng Long