Видалення символів за візерунком

Fish Shell:
Видалення символів за візерунком

Що і чому?

Pattern deletion removes specific characters from strings—like cleaning your text from unwanted symbols. Programmers use it to format data, scrub user input, or prepare text for processing.

How to:

Як це зробити:

Let’s delete vowels from a string. The string command does the heavy lifting.

set my_string "Vowels will vanish"
string replace -a -r "[aeiou]" "" -- $my_string

Output:

Vwls wll vnsh

Now, let’s strip numbers from filenames:

set filename "report_2023.txt"
string replace -a -r "[0-9]" "" -- $filename

Output:

report_.txt

Deep Dive

Занурення у деталі

Fish Shell debuted in 2005, focused on usability and scripting ease. Pattern deletion is built-in via string match, string replace commands, unlike POSIX shells that lean on grep, sed, or awk.

Alternatives? Sure. PowerShell’s -replace, Python’s .replace(), or good ol’ sed for a more traditional command-line approach.

As for Fish, it’s all about simplicity. No need to pipe echo output to sed when string replace can edit in-place or work with variables directly.

See Also

Дивіться також