content: recent stdout utilities
This commit is contained in:
parent
9a693538b0
commit
2ad86113c2
2 changed files with 52 additions and 0 deletions
29
zk/Delete_and_replace_characters_from_stdout_with_tr.md
Normal file
29
zk/Delete_and_replace_characters_from_stdout_with_tr.md
Normal 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'
|
||||||
23
zk/Truncate_stdout_with_cut.md
Normal file
23
zk/Truncate_stdout_with_cut.md
Normal 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
|
||||||
|
```
|
||||||
Loading…
Add table
Reference in a new issue