zawk = AWK + stdlib + Rust
|
length(s)
|
Length of s: utf-8 format
|
|
strlen(text)
|
Get bytes length
|
|
chat_at($1, 1)
|
Get char at index, starts from 1
|
|
match(s, re)
|
if string s matches the regular expression
|
|
substr(s, i[, j])
|
1-indexed substring of string s
|
|
sub(re, t, s)
|
Substitutes t for the first matching occurrence of regular
|
|
gsub(re, t, s)
|
Like sub, but with all occurrences substituted, not just the first.
|
|
index(s,t)
|
Position in string s where string t occurs, 0 if not found
|
|
last_index(s,t)
|
Last position in string s where string t occurs, 0 if not found
|
|
split(s, m[, fs])
|
Splits the string s according to fs, placing the results in the array m.
|
|
sprintf(fmt, s, ...)
|
Returns a string formatted according to fmt and provided arguments
|
|
printf(fmt, s, ...) [>[>] out]
|
Like sprintf but the result of the operation is written to standard output
|
|
hex(s)
|
Returns the hexadecimal integer (e.g. 0x123abc)
|
|
join_fields(i, j[, sep])
|
Returns columns i through j (1-indexed, inclusive) concatenated
|
|
join_csv(i, j)
|
Like join_fields but with columns joined by comma
|
|
join_tsv(i, j)
|
Like join_fields but with columns joined by tabs
|
|
tolower(s)
|
Returns a copy of s where all lowercase ASCII characters
|
|
toupper(s)
|
Returns a copy of s where all uppercase ASCII characters
|
|
strtonum(s)
|
numeric value(Decimal) strtonum("0x11")
|
|
trim(s), trim(s, "[]()")
|
Trim text with space by default
|
|
truncate(s,10)
|
Truncate s with width fixed
|
|
capitalize(s)
|
Capitalize first character of s
|
|
uncapitalize(s)
|
Uncapitalize first character of s
|
|
camel_case(s)
|
Return camel case of s: helloWorld
|
|
kebab_case(s)
|
Return kebab case of s: hello-world
|
|
snake_case(s)
|
Return snake case of s: hello_world
|
|
title_case(s)
|
Return kebab case of s: Hello World
|
|
isint(s)
|
Integer(64) or not for s
|
|
isnum(s)
|
Number(int or float) or not for s
|
|
starts_with(s, prefix)
|
Check s start with prefix or not
|
|
ends_with(s, suffix)
|
Check s end with prefix or not
|
|
contains(s, child)
|
Check s contains with prefix or not
|
|
mask(s)
|
Mask some sensitive text, such as email, phone
|
|
pad(s, 10, "*")
|
Pad s with width and place holder
|
|
strcmp(s1, s2)
|
Compare 2 text
|
|
lines(text)
|
Split text into none-empty lines
|
|
words(s)
|
Text to words array
|
|
repeat("*", 3)
|
Repeat text with times
|
|
default_if_empty(s, "0")
|
Return default value if text is empty or not exist.
|
|
append_if_missing(s, "/")
|
Add suffix if missing
|
|
preappend_if_missing(s, "https://")
|
Add prefix if missing
|
|
remove_if_begin("./demo.json", "./")
|
Remove prefix if available
|
|
remove_if_end("demo.json", ".json")
|
Remove suffix if available
|
|
quote(s)
|
Quote text if not quoted.
|
|
double_quote(s)
|
Double quote text if not quoted.
|
|
format_bytes(size)
|
Format bytes size: 10.1 MB
|
|
to_bytes("10.2 MB")
|
Convert bytes format to size
|
|
escape(format, s)
|
Escape s with format: json, csv, tsv, xml, sql, shell
|
|
escape_csv(s)
|
Escape s with CSV
|
|
last_part(text, sep)
|
Get last part with seperator
|
|
parse(text, template)
|
Parse text with wild match
|
|
rparse(text, regex)
|
Parse text with regex match group
|
|
fake(data, locale)
|
Generate fake data by locale
|
|
mkpass(length)
|
Generate password
|
|
figlet(text)
|
Generate figlet ascii art
|
parse("Hello World","{greet} {name}")["greet"]rparse("Hello World","(\\w+) (\\w+)")[1]|
url("https://example.com/path")
|
Parse s to URL array: schema, user, host, port ...
|
|
data_url("data:text/plain;base64,xxxx")
|
Parse data url: data_url("data:text/plain;base64,SGVsbG8sIFdvcmxkIQ==")
|
|
shlex("ls -al")
|
Parse command line to array
|
|
path("./demo.txt")
|
Parse path
|
|
semver("1.2.3-alpha")
|
Parse semantic version
|
|
pairs("id=1&name=Hello%20Wo")
|
Parse url query or normal pairs: "a=b,c=d"
|
|
record("requests_total{code=\"200\"}")
|
Parse pairs with name, such as Prometheus
|
|
message("name{a=1}(body)")
|
Parse message: name, headers and body
|
|
func("hello(1,2,3)")
|
Parse function call
|
|
flags("{vip,top20}")
|
Parse flags
|
|
variant("week(5)")
|
Parse variant
|
|
tuple("('first',1)")
|
Parse tuple
|
|
parse_array("['first','second']")
|
Parse array
|
|
read_all(file_path)
|
Read file into text
|
|
write_all(file_path, text)
|
Write text into file
|
|
getline()
|
Read line from file
|
|
read_config(file_path)
|
Read ini, properties into Map
|
|
system(cmd)
|
Execute cmd and return exit status
|
|
whoami()
|
user name
|
|
os()
|
OS name
|
|
arch()
|
such as x86_64, aarch64 ...
|
|
os_family()
|
unix or windows
|
|
pwd()
|
Current working directory
|
|
user_home()
|
User home directory
|
|
getenv(name,default_value)
|
Get env variable value
|
|
sqlite_query("sqlite.db",sql)
|
SQLite query: return value is array of CSV lines
|
|
sqlite_execute("sqlite.db", sql)
|
SQLite execute
|
|
libsql_query("http://localhost:8080",sql)
|
libSQL query: return value is array of CSV lines
|
|
libsql_execute("http://localhost:8080", sql)
|
libSQL execute
|
|
mysql_query(url, sql)
|
MySQL query: return value is array of CSV lines
|
|
mysql_execute(url, sql)
|
MySQL execute
|
|
pg_query(url, sql)
|
PostgreSQL query: return value is array of CSV lines
|
|
pg_execute(url, sql)
|
PostgreSQL execute
|
|
uuid()/uuid("v7")
|
Generate uuid: 128 bits
|
|
ulid()
|
Generat ulid: 128 bits
|
|
tsid()
|
Generate TSID
|
|
snowflake(machine_id)
|
Generate snowflake: 64 bits, max value for machine_id is 65535
|
|
length(arr)
|
Length of array
|
|
delete arr[1] / delete arr
|
Delete array item or array
|
|
seq(start, end, step)
|
Generate sequence array: seq command compatible
|
|
uniq(arr)
|
Unique items of array: uniq command compatible
|
|
_ = asort(arr)
|
Sort array items by asc
|
|
_max(arr)
|
Return max value of number array
|
|
_min(arr)
|
Return min value of number array
|
|
_sum(arr)
|
Return sum value of number array
|
|
_mean(arr)
|
Return man value of number array
|
|
_join(arr, ",")
|
Join array items to string
|
|
bf_insert(item)
|
Bloom filter insert
|
|
bf_contains(item)
|
Bloom filter contains
|
|
bf_icontains(item)
|
Bloom filter contains with insertion if not found
|
|
rand()
|
Random float number between 0 and 1
|
|
srand(x)
|
Seeds the random number generator used by rand
|
|
abs(x)
|
Absolute value of x
|
|
floor(x)
|
Return int floor value of x
|
|
ceil(x)
|
Return int ceil value of x
|
|
round(x)
|
Return int round value of x
|
|
fend(expression)
|
Calculate by fend: https://github.com/printfn/fend
|
|
min(x,y,z)
|
Return min value of x, y, z
|
|
max(x,y,z)
|
Return max value of x, y, z
|
|
mkbool(s)
|
Return 0 or 1 for bool string: false, true, Y, N ...
|
|
int(s)
|
Convert s to int
|
|
float(s)
|
Convert s to float
|
|
systime()
|
Current unix time
|
|
strftime()/strftime(p, timestamp)
|
Format timestamp by pattern
|
|
mktime(s)
|
Parse s to unix timestamp
|
|
datetime(s)
|
Parse s to date/time array
|
|
duration("2min + 12sec")
|
Parse expression to duration in seconds
|
|
from_json(json_text)
|
Parse json text to array
|
|
to_json(arr)
|
Output array as json text
|
|
json_value(json_text, json_path)
|
Get one text value by json path
|
|
json_query(json_text, json_path)
|
Query text values by json path
|
|
from_csv(line)
|
Parse CSV line to array
|
|
to_csv(arr)
|
Output array as CSV line
|
|
xml_value(xml_text, xpath)
|
Get text value by xpath
|
|
xml_query(xml_text, xpath)
|
Query text values by xpath
|
|
html_value(html_text, selector)
|
Get text value by css selector
|
|
html_query(html_text, selector)
|
Query text values by css selector
|
|
encode(format, s)
|
Encode s with format
|
|
decode(format, s)
|
Decode s with format
|
|
digest(algorithm, s)
|
Digest s with algorithm
|
|
hmac(algorithm, secret-key, s)
|
hmac s with: HmacSHA256, HmacSHA512
|
|
jwt("HS256", secret-key, arr-payload)
|
Generate JWT token: HS256, HS384, HS512
|
|
dejwt(secret-key, token)
|
Verify JWT token and return payload array
|
|
encrypt("aes-128-cbc", "Secret Text", "pass_key")
|
Encrypt secret text
|
|
decrypt("aes-128-cbc", "7b9c07..", "pass_key")
|
Decrypt to plain text
|
|
http_get(url,headers)
|
Return HTTP response
|
|
http_post(url, headers, body)
|
Return HTTP response
|
|
send_mail(from,to,subject,body)
|
Send email by REST
|
|
smtp_send(url, from,to,subject,body)
|
Send email by SMTP
|
|
s3_get(bucket, object_name)
|
Return the text value of object
|
|
s3_put(bucket, object_name, body)
|
Put the text body to s3 bucket
|
|
publish(nats_mqtt_url, body)
|
Publish message to NATS
|
MLSN_API_KEY: API key for MailerSendsmtp://localhost:1025smtps://user:password@host:465|
kv_get(ns, key)
|
Get value by namespace and key
|
|
kv_put(ns, key, value)
|
Put value by namespace and key
|
|
kv_delete(ns, key)
|
Delete value by namespace and key
|
|
kv_clear(ns)
|
Clear all keys
|
|
hex2rgb("#FF0000")
|
Conert hex color to RGB array
|
|
rgb2hex(r,g,b)
|
Convert RGB to hex
|
|
var_dump(value)
|
Dump and output variable to console with json format
|
|
log_debug(msg)/log_info/log_warn/log_error
|
Log s and output to console
|
|
isarray(x)
|
Is array or not
|
|
typeof(x)
|
Type name of x: array, number, string, unassigned
|
|
AWK Cheat Sheet
|
|
|
Awk in 20 Minutes
|
|
|
Gawk: Effective AWK Programming
|
No comments yet.
Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.