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 +```