content: recent stdout utilities

This commit is contained in:
Thomas Bishop 2025-11-06 18:43:00 +00:00
parent 9a693538b0
commit 2ad86113c2
2 changed files with 52 additions and 0 deletions

View file

@ -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'

View file

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