Skip to main content

๐Ÿ”ค String Manipulation Tools

Utilities for working with strings.


split_stringโ€‹

Splits text based on a delimiter.

ArgumentDescription
SEPSeparator pattern
TEXTText 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.

ArgumentDescription
SEPSeparator pattern
NNumber of splits to keep
TEXTText 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.

ArgumentDescription
SEPSeparator pattern
NIndex of result to return
TEXTText 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.

ArgumentDescription
NNumber of repetitions
TEXTText to repeat
repeat 5 OLE  # Returns: OLEOLEOLEOLEOLE

stringโ€‹

Multi-utility tool for string manipulation.

FlagDescription
replace OLD NEWReplace OLD with NEW (multiple allowed)
replace_line OLD NEWReplace lines containing OLD with NEW (multiple allowed)
remove TEXTRemove TEXT (multiple allowed)
inside START ENDExtract text between START and END
extract START ENDExtract content between lines START and END
complete_extract START ENDInclude START/END lines in extraction
-after-line LINE TEXTAdd TEXT after LINE (multiple allowed)
-before-line LINE TEXTAdd TEXT before LINE (multiple allowed)
escapeEscape special characters (e.g., , $, *)
upperConvert to uppercase
lowerConvert to lowercase
countReturn character count
-rApply recursively (all occurrences)
-p PATTERNFilter extract results by PATTERN
-f FILELoad text from FILE
TEXTString 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"