text: add a script to trim whitespace
- ID
e6f4c99- date
2026-05-27 06:54:27+00:00- author
Alex Chan <alex@alexwlchan.net>- parent
cd13b60- message
text: add a script to trim whitespace- changed files
2 files, 30 additions, 1 deletion
Changed files
text/README.md (6469) → text/README.md (6766)
diff --git a/text/README.md b/text/README.md
index 4c653cd..c8fc07e 100644
--- a/text/README.md
+++ b/text/README.md
@@ -87,6 +87,10 @@ scripts = [
"description": "prints a tally of lines in the given text.",
},
{
+ "usage": "trim < [PATH]",
+ "description": "prints text with whitespace stripped",
+ },
+ {
"usage": "vs [PATH]",
"description": "open a path in Visual Studio Code",
},
@@ -218,6 +222,15 @@ cog_helpers.create_description_table(folder_name=folder_name, scripts=scripts)
</dd>
<dt>
+ <a href="https://github.com/alexwlchan/scripts/blob/main/text/trim">
+ <code>trim < [PATH]</code>
+ </a>
+ </dt>
+ <dd>
+ prints text with whitespace stripped
+ </dd>
+
+ <dt>
<a href="https://github.com/alexwlchan/scripts/blob/main/text/vs">
<code>vs [PATH]</code>
</a>
@@ -226,4 +239,4 @@ cog_helpers.create_description_table(folder_name=folder_name, scripts=scripts)
open a path in Visual Studio Code
</dd>
</dl>
-<!-- [[[end]]] (sum: YMjzg7VZH5) -->
\ No newline at end of file
+<!-- [[[end]]] (sum: vgRPKLXa0Q) -->
\ No newline at end of file
text/trim (0) → text/trim (252)
diff --git a/text/trim b/text/trim
new file mode 100755
index 0000000..6a887e7
--- /dev/null
+++ b/text/trim
@@ -0,0 +1,16 @@
+#!/usr/bin/env python3
+"""
+Trim removes leading/trailing whitespace from a string passed on stdin.
+
+Usage:
+
+ $ echo " hello world " | trim
+ hello world
+
+"""
+
+import sys
+
+
+if __name__ == '__main__':
+ sys.stdout.write(sys.stdin.read().strip())