From 2ad86113c238a689b7fe7616b991a23feb5e632b Mon Sep 17 00:00:00 2001 From: thomasabishop Date: Thu, 6 Nov 2025 18:43:00 +0000 Subject: [PATCH] content: recent stdout utilities --- ..._replace_characters_from_stdout_with_tr.md | 29 +++++++++++++++++++ zk/Truncate_stdout_with_cut.md | 23 +++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 zk/Delete_and_replace_characters_from_stdout_with_tr.md create mode 100644 zk/Truncate_stdout_with_cut.md diff --git a/zk/Delete_and_replace_characters_from_stdout_with_tr.md b/zk/Delete_and_replace_characters_from_stdout_with_tr.md new file mode 100644 index 0000000..fef4441 --- /dev/null +++ b/zk/Delete_and_replace_characters_from_stdout_with_tr.md @@ -0,0 +1,29 @@ +--- +tags: + - Linux + - procedural +--- + +# Delete and replace characters from stdout with `tr` + +I used the following pattern to remove new lines and blank spaces: + +```sh +tr -ds '\n' " " +``` + +Everything after the flags are considered an array. You can multiply actions on +the same target or attack two different targets such as is the case with this +example. + +First flag is "delete". In the exsample this deletes new lines. Second flag is +"squeeze repeats". In the example this removes all repeated spaces. + +```sh +ls | tail | tr -s a z + +# zpple.txt +# pzckzge.json +``` + +In this example, squeeze replaces all instances of 'a' with 'z' diff --git a/zk/Truncate_stdout_with_cut.md b/zk/Truncate_stdout_with_cut.md new file mode 100644 index 0000000..5571132 --- /dev/null +++ b/zk/Truncate_stdout_with_cut.md @@ -0,0 +1,23 @@ +--- +tags: + - Linux + - procedural +--- + +# Truncate stdout with `cut` + +Pass in `-c` to truncate characters or `-b` to truncate bytes. + +Return the first three characters of "Thomas": + +```sh +echo 'thomas' | cut -c -3 +# tho +``` + +Return "Thomas" minus the first three chracters: + +```sh +echo 'thomas' | cut -c 3- +# omas +```