Return a string with za colour codes replaced with ANSI values.
Example:
# Example for addansi
println addansi("[#2]Red Text[#-]")
Returns an ANSI code string for expressing an 8-bit background colour code.
Example:
# Example for bg256 println bg256(3.14)
Returns an ANSI code string for expressing an rgb background colour code.
Example:
# Example for bgrgb println bgrgb(3.14, 3.14, 3.14)
Format the input string in the manner of fprintf(). Also processes embedded colour codes to ANSI.
Example:
# Example for ccformat
println ccformat("[#2]Error[#-]: %s (code: %d)", "File not found", 404)
Remove curly brace nests from a string.
Example:
# Example for clean text = "password=secret123&api_key=abc123&token=xyz789" println clean(text)
Turns a newline separated string into a space separated string.
Example:
# Example for collapse
println collapse("hello world\n\n\nfoo bar")
Returns the number of lines in string_name.
Example:
# Example for count text = "line1\nline2\nline3" println count(text)
Returns an ANSI code string for expressing an 8-bit foreground colour code.
Example:
# Example for fg256 println fg256(3.14)
Returns an ANSI code string for expressing an rgb foreground colour code.
Example:
# Example for fgrgb println fgrgb(3.14, 3.14, 3.14)
Retrieves columnar field position from input_string.
optional_separator defaults to a space character. string is empty on failure.
Example:
# Example for field
field("hello", 42) # usage
Splits up input_string in local array F, with fields starting at index 1.
Field count is stored in NF. Also squeezes repeat spaces when separator is a space char (default).
Returns -1 on error, or field count.
Example:
# Example for fields
fields("hello") # usage
Returns a string matching the regular expression regex in string. count should be -1 for all matches.
Example:
# Example for filter text = "The quick brown fox jumps over the lazy dog" println filter(text, "[aeiou]+")
Format the input string in the manner of fprintf().
Example:
# Example for format
println format("Hello %s, you have %d messages", "Alice", 5)
Returns the value of the key key_name in string_array.
Example:
# Example for get_value
println get_value("name=John\nage=30", "name")
Alias for line_filter.
Example:
# Example for grep text = "apple\nbanana\ncherry\napricot" println grep(text, "^a")
Returns string with all matches of string_m replaced with string_s.
Example:
# Example for gsub
println gsub("hello world", "l", "L")
Does string1 end with string2?
Example:
# Example for has_end
println has_end("hello world", "world")
Does string1 begin with string2?
Example:
# Example for has_start
println has_start("hello world", "hello")
Left pads each line of nl_string with distance cursor right commands.
Example:
# Example for inset
println inset("hello", 3)
println inset("hello world", 20)
Checks for utf8 rune and returns width. 1 on no match.
Example:
# Example for is_utf8
println is_utf8("hello")
println is_utf8("\xff\xfe")
Returns a string with all elements of string_list concatenated, separated by fs.
Example:
# Example for join println join(["a", "b", "c"])
Returns a list of map keys
Example:
# Example for keys println keys(map(.a 1, .b 2))
Calculate Levenshtein edit distance between two strings.
Example:
# Example for levdist
println levdist("kitten", "sitting")
println levdist("saturday", "sunday")
Append a line to array string var.
Example:
# Example for line_add text = "apple\nbanana" println line_add(text, "cherry")
Inserts a new line to array string var after the first matching regex.
Example:
# Example for line_add_after text = "apple\nbanana\ncherry" println line_add_after(text, "banana", "blueberry")
Inserts a new line in string ahead of the first matching regex_string.
Example:
# Example for line_add_before text = "apple\nbanana\ncherry" println line_add_before(text, "banana", "apricot")
Remove lines from array string var which match regex.
Example:
# Example for line_delete
println line_delete("hello\nworld\ntest", "world")
Returns lines from nl_string where regular expression regex matches.
Example:
# Example for line_filter text = "apple\nbanana\ncherry" println line_filter(text, "an")
Returns the top count lines of nl_string.
Example:
# Example for line_head text = "line1\nline2\nline3" println line_head(text, 2)
Does nl_string contain a match for regular expression regex on any line?
Example:
# Example for line_match text = "apple\nbanana\ncherry" println line_match(text, "an")
Replaces lines in var that match regex with replacement.
Example:
# Example for line_replace text = "apple\nbanana\ncherry" println line_replace(text, "banana", "blueberry")
Returns the last count lines of nl_string.
Example:
# Example for line_tail text = "line1\nline2\nline3" println line_tail(text, 2)
Returns lines from string_name. string_range is specified in the form start:end.
Either optional term can be last to indicate the last line of the file. Numbering starts from 0.
Example:
# Example for lines text = "line1\nline2\nline3" println lines(text, "1:2")
Format the input string.
Example:
# Example for literal
literal("Hello %s, you have %d messages\n", "Alice", 5)
Convert to lower-case.
Example:
# Example for lower
println lower("Hello World")
Does string contain a match for regular expression regex?
Example:
# Example for match
println match("hello world", "world")
Returns the next line number which contains the regex in nl_string. -1 is returned on no match.
Example:
# Example for next_match
println next_match("hello world", "l", 0)
println next_match("hello world", "l", 3)
Return left (-1), centred (0) or right (1) justified, padded string.
Example:
# Example for pad
println pad("hello", 0, 10)
println pad("hello", -1, 10, "-")
println pad("hello", 1, 10, "-")
Returns a cursor positioning ANSI code string for (row,col).
Example:
# Example for pos print pos(1, 1) println "Cursor repositioned"
Returns a progress bar string.
Example:
# Example for progress_bar
try
progress_bar(50, 100)
catch err
println "Error"
endtry
Replaces matches found in var with regex to replacement.
Example:
# Example for replace
println replace("hello world", "world", "everyone")
Reverse the contents of a variable.
Example:
# Example for reverse println reverse([1, 2, 3, 4, 5])
Checks if a regex has valid syntax.
Example:
# Example for rvalid
println rvalid("^[a-z]+$")
println rvalid("[invalid")
Search file for regex pattern with context. Options: .regex (required), .before (int), .after (int), .number (bool), .only_matching (bool).
Returns array of maps with line data and context. (map fields: .line,.linenum,.context_before_count,.context_after_count,.context_before[],.context_after[],.text[] when .only_matching=true
Example:
# Example for sgrep
write_file("/tmp/za_sgrep.txt", "hello
world")
sgrep("/tmp/za_sgrep.txt", map(.regex "hello"))
Returns string as a list, breaking the string on fs.
Example:
# Example for split
println split("a,b,c", ",")
Remove escaped ansi codes.
Example:
# Example for stripansi
text = addansi("[#2]Red Text[#-]")
println stripansi(text)
Remove Za colour codes from string.
Example:
# Example for stripcc
println stripcc("[#2]Red Text[#-] and [#4]Green Text[#-]")
Remove outer quotes (double, single or backtick)
Example:
# Example for stripquotes
println stripquotes('"hello world"')
println stripquotes("'single quoted'")
Returns the position of the next match of substring in string. Returns -1 if no match found.
Example:
# Example for strpos
println strpos("hello world", "world")
Returns a sub-string of string, from position int_s with length int_l.
Example:
# Example for substr
println substr("hello world", 0, 5)
delete (action "d") or squeeze (action "s") extra characters (in case_string) from string.
Translate (action "t") can be used, along with the optional translation_string to specify direct
replacements for existing characters. Please note: this is a very restricted subset of the tr tool.
Example:
# Example for tr
println tr("hello world", "lo", "12")
Removes whitespace from string, depending on int_type.
-1 ltrim, 0 both, 1 rtrim. By default, space (ASCII:32) and horizontal tabs (ASCII:9) are removed.
Example:
# Example for trim
println trim(" hello world ", 0)
println trim(" hello world ", -1)
println trim(" hello world ", 1)
println trim("--hello world--", 0, "-")
Truncates string to width runes, appending ellipsis if truncated.
Example:
# Example for trunc
println trunc("The quick brown fox jumps over the lazy dog", 20)
println trunc("hello world", 5, "..")
Convert to upper-case.
Example:
# Example for upper
println upper("Hello World")
Returns a list of map values
Example:
# Example for values println values(map(.a 1, .b 2))
Enable (true) or disable (false) line wrap in non-global display panes.
The previous wrap value is returned.
N.B. ensure that only plain text is wrapped. ANSI codes may be split!
Example:
# Example for wrap wrap() # usage
Wrap text at console width (default) or specified width, preserving words and ANSI codes.
Example:
# Example for wrap_text text = "The quick brown fox jumps over the lazy dog." println wrap_text(text, 20)