๐ค String Manipulation Tools
Utilities for working with strings.
split_stringโ
Splits text based on a delimiter.
Argument | Description |
---|---|
SEP | Separator pattern |
TEXT | Text to split |
split_string ":" "A B: C D E: FG" # Returns: A B, C D E, FG
split_string "word" "A Bword C D E word FG" # Returns: A B, C D E, FG
split_cutโ
Splits text and returns up to the nth result.
Argument | Description |
---|---|
SEP | Separator pattern |
N | Number of splits to keep |
TEXT | Text to split |
split_cut ":" 2 "A B: C D E: FG" # Returns: A B, C D E
split_cut "word" 1 "A Bword C D E word FG" # Returns: A B
split_extractโ
Splits text and returns the nth result.
Argument | Description |
---|---|
SEP | Separator pattern |
N | Index of result to return |
TEXT | Text to split |
split_extract ":" 2 "A B: C D E: FG" # Returns: C D E
split_extract "word" 3 "A Bword C D E word FG" # Returns: FG
repeatโ
Repeats text a specified number of times.
Argument | Description |
---|---|
N | Number of repetitions |
TEXT | Text to repeat |
repeat 5 OLE # Returns: OLEOLEOLEOLEOLE
stringโ
Multi-utility tool for string manipulation.
Flag | Description |
---|---|
replace OLD NEW | Replace OLD with NEW (multiple allowed) |
replace_line OLD NEW | Replace lines containing OLD with NEW (multiple allowed) |
remove TEXT | Remove TEXT (multiple allowed) |
inside START END | Extract text between START and END |
extract START END | Extract content between lines START and END |
complete_extract START END | Include START/END lines in extraction |
-after-line LINE TEXT | Add TEXT after LINE (multiple allowed) |
-before-line LINE TEXT | Add TEXT before LINE (multiple allowed) |
escape | Escape special characters (e.g., , $, *) |
upper | Convert to uppercase |
lower | Convert to lowercase |
count | Return character count |
-r | Apply recursively (all occurrences) |
-p PATTERN | Filter extract results by PATTERN |
-f FILE | Load text from FILE |
TEXT | String to process |
# Replace
string replace "A" "B" "Hi, A will be replaced with B"
# Recursive replace
string -r replace "A" "B" "Hi, AAAA will be replaced with B"
# Remove
string -r remove "A" "This AAAAAA will be removed"
# Inside
string inside "A" "B" "Hi A this content will be return B sayonara"
# Uppercase
string upper "this content will be return as uppercase"
# Lowercase
string lower "THIS CONTENT WILL BE RETURN AS LOWERCASE"
# Multiple actions
string remove "A" remove "B" replace "C" "Ole" "ABC text"
# Extract with pattern
example="
Hi,
Hello world
A
B
C
Okay, sayonara
Hello world 2
D
E
F
sayonara again
"
string -r -p "E" extract "world" "sayonara" "$example"
# Add lines
string -after-line "world" "ADD this after" "$example"