\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{linux\_china} \pdfinfo{ /Title (zawk.pdf) /Creator (Cheatography) /Author (linux\_china) /Subject (zawk Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{0078C4} \definecolor{LightBackground}{HTML}{EFF6FB} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{zawk Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{linux\_china} via \textcolor{DarkBackground}{\uline{cheatography.com/141366/cs/42735/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}linux\_china \\ \uline{cheatography.com/linux-china} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Published 15th March, 2024.\\ Updated 7th October, 2024.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{multicols*}{2} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Install zawk}} \tn \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{\$ cargo install zawk \newline % Row Count 1 (+ 1) \$ brew install linux-china/tap/zawk \newline % Row Count 2 (+ 1) \$ sudo xattr -r -d com.apple.quarantine \$(readlink -f \$(brew -{}-prefix zawk))/bin/zawk% Row Count 4 (+ 2) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{how to run zawk?}} \tn \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{\$ zawk 'BEGIN \{ print strftime(), whoami() \}' \newline % Row Count 1 (+ 1) \$ zawk -f demo.awk demo.txt% Row Count 2 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.76 cm} x{4.24 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{String functions: utf-8 by default}} \tn % Row 0 \SetRowColor{LightBackground} length(s) & Length of s: utf-8 format \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} chat\_at(\$1, 1) & Get char at index, starts from 1 \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} match(s, re) & if string s matches the regular expression \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} substr(s, i{[}, j{]}) & 1-indexed substring of string s \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} sub(re, t, s) & Substitutes t for the first matching occurrence of regular \tn % Row Count 11 (+ 3) % Row 5 \SetRowColor{white} gsub(re, t, s) & Like sub, but with all occurrences substituted, not just the first. \tn % Row Count 15 (+ 4) % Row 6 \SetRowColor{LightBackground} index(s,t) & Position in string s where string t occurs, 0 if not found \tn % Row Count 18 (+ 3) % Row 7 \SetRowColor{white} last\_index(s,t) & Last position in string s where string t occurs, 0 if not found \tn % Row Count 21 (+ 3) % Row 8 \SetRowColor{LightBackground} split(s, m{[}, fs{]}) & Splits the string s according to fs, placing the results in the array m. \tn % Row Count 25 (+ 4) % Row 9 \SetRowColor{white} sprintf(fmt, s, ...) & Returns a string formatted according to fmt and provided arguments \tn % Row Count 29 (+ 4) % Row 10 \SetRowColor{LightBackground} printf(fmt, s, ...) {[}\textgreater{}{[}\textgreater{}{]} out{]} & Like sprintf but the result of the operation is written to standard output \tn % Row Count 33 (+ 4) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{3.76 cm} x{4.24 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{String functions: utf-8 by default (cont)}} \tn % Row 11 \SetRowColor{LightBackground} hex(s) & Returns the hexadecimal integer (e.g. 0x123abc) \tn % Row Count 3 (+ 3) % Row 12 \SetRowColor{white} join\_fields(i, j{[}, sep{]}) & Returns columns i through j (1-indexed, inclusive) concatenated \tn % Row Count 6 (+ 3) % Row 13 \SetRowColor{LightBackground} join\_csv(i, j) & Like join\_fields but with columns joined by comma \tn % Row Count 9 (+ 3) % Row 14 \SetRowColor{white} join\_tsv(i, j) & Like join\_fields but with columns joined by tabs \tn % Row Count 12 (+ 3) % Row 15 \SetRowColor{LightBackground} tolower(s) & Returns a copy of s where all lowercase ASCII characters \tn % Row Count 15 (+ 3) % Row 16 \SetRowColor{white} toupper(s) & Returns a copy of s where all uppercase ASCII characters \tn % Row Count 18 (+ 3) % Row 17 \SetRowColor{LightBackground} strtonum(s) & numeric value(Decimal) strtonum("0x11") \tn % Row Count 20 (+ 2) % Row 18 \SetRowColor{white} trim(s), trim(s, "{[}{]}()") & Trim text with space by default \tn % Row Count 22 (+ 2) % Row 19 \SetRowColor{LightBackground} truncate(s,10) & Truncate s with width fixed \tn % Row Count 24 (+ 2) % Row 20 \SetRowColor{white} capitalize(s) & Capitalize first character of s \tn % Row Count 26 (+ 2) % Row 21 \SetRowColor{LightBackground} uncapitalize(s) & Uncapitalize first character of s \tn % Row Count 28 (+ 2) % Row 22 \SetRowColor{white} camel\_case(s) & Return camel case of s: helloWorld \tn % Row Count 30 (+ 2) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{3.76 cm} x{4.24 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{String functions: utf-8 by default (cont)}} \tn % Row 23 \SetRowColor{LightBackground} kebab\_case(s) & Return kebab case of s: hello-world \tn % Row Count 2 (+ 2) % Row 24 \SetRowColor{white} snake\_case(s) & Return snake case of s: hello\_world \tn % Row Count 4 (+ 2) % Row 25 \SetRowColor{LightBackground} title\_case(s) & Return kebab case of s: Hello World \tn % Row Count 6 (+ 2) % Row 26 \SetRowColor{white} isint(s) & Integer(64) or not for s \tn % Row Count 8 (+ 2) % Row 27 \SetRowColor{LightBackground} isnum(s) & Number(int or float) or not for s \tn % Row Count 10 (+ 2) % Row 28 \SetRowColor{white} starts\_with(s, prefix) & Check s start with prefix or not \tn % Row Count 12 (+ 2) % Row 29 \SetRowColor{LightBackground} ends\_with(s, suffix) & Check s end with prefix or not \tn % Row Count 14 (+ 2) % Row 30 \SetRowColor{white} contains(s, child) & Check s contains with prefix or not \tn % Row Count 16 (+ 2) % Row 31 \SetRowColor{LightBackground} mask(s) & Mask some sensitive text, such as email, phone \tn % Row Count 19 (+ 3) % Row 32 \SetRowColor{white} pad(s, 10, "*") & Pad s with width and place holder \tn % Row Count 21 (+ 2) % Row 33 \SetRowColor{LightBackground} strcmp(s1, s2) & Compare 2 text \tn % Row Count 22 (+ 1) % Row 34 \SetRowColor{white} lines(text) & Split text into none-empty lines \tn % Row Count 24 (+ 2) % Row 35 \SetRowColor{LightBackground} words(s) & Text to words array \tn % Row Count 25 (+ 1) % Row 36 \SetRowColor{white} repeat("*", 3) & Repeat text with times \tn % Row Count 27 (+ 2) % Row 37 \SetRowColor{LightBackground} \seqsplit{default\_if\_empty(s}, "0") & Return default value if text is empty or not exist. \tn % Row Count 30 (+ 3) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{3.76 cm} x{4.24 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{String functions: utf-8 by default (cont)}} \tn % Row 38 \SetRowColor{LightBackground} \seqsplit{append\_if\_missing(s}, "/") & Add suffix if missing \tn % Row Count 2 (+ 2) % Row 39 \SetRowColor{white} \seqsplit{preappend\_if\_missing(s}, "https://") & Add prefix if missing \tn % Row Count 4 (+ 2) % Row 40 \SetRowColor{LightBackground} \seqsplit{remove\_if\_begin("}./demo.json", "./") & Remove prefix if available \tn % Row Count 6 (+ 2) % Row 41 \SetRowColor{white} \seqsplit{remove\_if\_end("demo}.json", ".json") & Remove suffix if available \tn % Row Count 8 (+ 2) % Row 42 \SetRowColor{LightBackground} quote(s) & Quote text if not quoted. \tn % Row Count 10 (+ 2) % Row 43 \SetRowColor{white} double\_quote(s) & Double quote text if not quoted. \tn % Row Count 12 (+ 2) % Row 44 \SetRowColor{LightBackground} \seqsplit{format\_bytes(size)} & Format bytes size: 10.1 MB \tn % Row Count 14 (+ 2) % Row 45 \SetRowColor{white} to\_bytes("10.2 MB") & Convert bytes format to size \tn % Row Count 16 (+ 2) % Row 46 \SetRowColor{LightBackground} escape(format, s) & Escape s with format: json, csv, tsv, xml, sql, shell \tn % Row Count 19 (+ 3) % Row 47 \SetRowColor{white} escape\_csv(s) & Escape s with CSV \tn % Row Count 20 (+ 1) % Row 48 \SetRowColor{LightBackground} last\_part(text, sep) & Get last part with seperator \tn % Row Count 22 (+ 2) % Row 49 \SetRowColor{white} parse(text, template) & Parse text with wild match \tn % Row Count 24 (+ 2) % Row 50 \SetRowColor{LightBackground} rparse(text, regex) & Parse text with regex match group \tn % Row Count 26 (+ 2) % Row 51 \SetRowColor{white} fake(data, locale) & Generate fake data by locale \tn % Row Count 28 (+ 2) % Row 52 \SetRowColor{LightBackground} mkpass(length) & Generate password \tn % Row Count 29 (+ 1) % Row 53 \SetRowColor{white} figlet(text) & Generate figlet ascii art \tn % Row Count 31 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{- parse: use wild match - `parse("Hello World","\{greet\} \{name\}"){[}"greet"{]}` \newline - rparse: use regex group - `rparse("Hello World","(\textbackslash{}\textbackslash{}w+) (\textbackslash{}\textbackslash{}w+)"){[}1{]}` \newline \newline \# fake function restriction \newline {\emph{ data: name, phone, cell, email, ip,creditcard,wechat,id,zipcode,plate \newline }} locale: en, cn} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.92 cm} x{4.08 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Text Parser}} \tn % Row 0 \SetRowColor{LightBackground} \seqsplit{url("https://example}.com/path") & Parse s to URL array: schema, user, host, port ... \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} \seqsplit{data\_url("data:text/plain;base64},xxxx") & Parse data url: \seqsplit{data\_url("data:text/plain;base64},SGVsbG8sIFdvcmxkIQ==") \tn % Row Count 7 (+ 4) % Row 2 \SetRowColor{LightBackground} shlex("ls -al") & Parse command line to array \tn % Row Count 9 (+ 2) % Row 3 \SetRowColor{white} path("./demo.txt") & Parse path \tn % Row Count 10 (+ 1) % Row 4 \SetRowColor{LightBackground} \seqsplit{semver("1.2.3-alpha")} & Parse semantic version \tn % Row Count 12 (+ 2) % Row 5 \SetRowColor{white} \seqsplit{pairs("id=1\&name=Hello\%20Wo")} & Parse url query or normal pairs: "a=b,c=d" \tn % Row Count 15 (+ 3) % Row 6 \SetRowColor{LightBackground} record("requests\_total\{code=\textbackslash{}"200\textbackslash{}"\}") & Parse pairs with name, such as Prometheus \tn % Row Count 18 (+ 3) % Row 7 \SetRowColor{white} message("name\{a=1\}(body)") & Parse message: name, headers and body \tn % Row Count 20 (+ 2) % Row 8 \SetRowColor{LightBackground} func("hello(1,2,3)") & Parse function call \tn % Row Count 22 (+ 2) % Row 9 \SetRowColor{white} flags("\{vip,top20\}") & Parse flags \tn % Row Count 24 (+ 2) % Row 10 \SetRowColor{LightBackground} variant("week(5)") & Parse variant \tn % Row Count 25 (+ 1) % Row 11 \SetRowColor{white} tuple("('first',1)") & Parse tuple \tn % Row Count 27 (+ 2) % Row 12 \SetRowColor{LightBackground} parse\_array("{[}'first','second'{]}") & Parse array \tn % Row Count 29 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.76 cm} x{4.24 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{I/O functions}} \tn % Row 0 \SetRowColor{LightBackground} \seqsplit{read\_all(file\_path)} & Read file into text \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \seqsplit{write\_all(file\_path}, text) & Write text into file \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} getline() & Read line from file \tn % Row Count 5 (+ 1) % Row 3 \SetRowColor{white} \seqsplit{read\_config(file\_path)} & Read ini, properties into Map \tn % Row Count 7 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{getline: \newline - \seqsplit{https://www.gnu.org/software/gawk/manual/html\_node/Getline.html} \newline - \seqsplit{http://awk.freeshell.org/AllAboutGetline}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{1.92 cm} x{6.08 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{OS functions}} \tn % Row 0 \SetRowColor{LightBackground} \seqsplit{system(cmd)} & Execute cmd and return exit status \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} whoami() & user name \tn % Row Count 3 (+ 1) % Row 2 \SetRowColor{LightBackground} os() & OS name \tn % Row Count 4 (+ 1) % Row 3 \SetRowColor{white} arch() & such as x86\_64, aarch64 ... \tn % Row Count 5 (+ 1) % Row 4 \SetRowColor{LightBackground} \seqsplit{os\_family()} & unix or windows \tn % Row Count 7 (+ 2) % Row 5 \SetRowColor{white} pwd() & Current working directory \tn % Row Count 8 (+ 1) % Row 6 \SetRowColor{LightBackground} \seqsplit{user\_home()} & User home directory \tn % Row Count 10 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Database functions}} \tn % Row 0 \SetRowColor{LightBackground} \seqsplit{sqlite\_query("sqlite}.db",sql) & SQLite query: return value is array of CSV lines \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} \seqsplit{sqlite\_execute("sqlite}.db", sql) & SQLite execute \tn % Row Count 5 (+ 2) % Row 2 \SetRowColor{LightBackground} \seqsplit{libsql\_query("http://localhost:8080"},sql) & libSQL query: return value is array of CSV lines \tn % Row Count 8 (+ 3) % Row 3 \SetRowColor{white} \seqsplit{libsql\_execute("http://localhost:8080"}, sql) & libSQL execute \tn % Row Count 11 (+ 3) % Row 4 \SetRowColor{LightBackground} mysql\_query(url, sql) & MySQL query: return value is array of CSV lines \tn % Row Count 14 (+ 3) % Row 5 \SetRowColor{white} mysql\_execute(url, sql) & MySQL execute \tn % Row Count 16 (+ 2) % Row 6 \SetRowColor{LightBackground} pg\_query(url, sql) & PostgreSQL query: return value is array of CSV lines \tn % Row Count 19 (+ 3) % Row 7 \SetRowColor{white} pg\_execute(url, sql) & PostgreSQL execute \tn % Row Count 20 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{MySQL url: \seqsplit{mysql://root:123456@localhost:3306/test} \newline PostgreSQL url: \seqsplit{postgresql://postgres:postgres@localhost/db\_name}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Misc commands}} \tn \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{\# dump prometheus text to CSV \newline % Row Count 1 (+ 1) \$ zawk dump -{}-prometheus \seqsplit{http://localhost:8080/actuator/prometheus} \newline % Row Count 3 (+ 2) \# parse CSV \newline % Row Count 4 (+ 1) \$ zawk -f demo.awk -i csv demo.csv \newline % Row Count 5 (+ 1) \# Nushell \newline % Row Count 6 (+ 1) \$ ls | to csv | \textasciicircum{}zawk -i csv '\{print \$1\}'% Row Count 7 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{p{1.04 cm} x{6.96 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{AWK \& Friends}} \tn % Row 0 \SetRowColor{LightBackground} grep & \seqsplit{https://www.gnu.org/s/grep/manual/grep.html} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} sed & \seqsplit{https://www.gnu.org/software/sed/manual/sed.html} \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} \seqsplit{DuckDB} & https://duckdb.org/ \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} xsv & \seqsplit{https://github.com/BurntSushi/xsv} \tn % Row Count 7 (+ 1) % Row 4 \SetRowColor{LightBackground} jq & \seqsplit{https://jqlang.github.io/jq/} \tn % Row Count 8 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{2.72 cm} x{5.28 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{ID generator}} \tn % Row 0 \SetRowColor{LightBackground} \seqsplit{uuid()/uuid("v7")} & Generate uuid: 128 bits \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} ulid() & Generat ulid: 128 bits \tn % Row Count 3 (+ 1) % Row 2 \SetRowColor{LightBackground} tsid() & Generate TSID \tn % Row Count 4 (+ 1) % Row 3 \SetRowColor{white} \seqsplit{snowflake(machine\_id)} & Generate snowflake: 64 bits, max value for machine\_id is 65535 \tn % Row Count 7 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.12 cm} x{4.88 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Array functions}} \tn % Row 0 \SetRowColor{LightBackground} length(arr) & Length of array \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} delete arr{[}1{]} / delete arr & Delete array item or array \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} seq(start, end, step) & Generate sequence array: seq command compatible \tn % Row Count 5 (+ 2) % Row 3 \SetRowColor{white} uniq(arr) & Unique items of array: uniq command compatible \tn % Row Count 7 (+ 2) % Row 4 \SetRowColor{LightBackground} \_ = asort(arr) & Sort array items by asc \tn % Row Count 8 (+ 1) % Row 5 \SetRowColor{white} \_max(arr) & Return max value of number array \tn % Row Count 10 (+ 2) % Row 6 \SetRowColor{LightBackground} \_min(arr) & Return min value of number array \tn % Row Count 12 (+ 2) % Row 7 \SetRowColor{white} \_sum(arr) & Return sum value of number array \tn % Row Count 14 (+ 2) % Row 8 \SetRowColor{LightBackground} \_mean(arr) & Return man value of number array \tn % Row Count 16 (+ 2) % Row 9 \SetRowColor{white} \_join(arr, ",") & Join array items to string \tn % Row Count 18 (+ 2) % Row 10 \SetRowColor{LightBackground} \seqsplit{bf\_insert(item)} & Bloom filter insert \tn % Row Count 19 (+ 1) % Row 11 \SetRowColor{white} \seqsplit{bf\_contains(item)} & Bloom filter contains \tn % Row Count 21 (+ 2) % Row 12 \SetRowColor{LightBackground} \seqsplit{bf\_icontains(item)} & Bloom filter contains with insertion if not found \tn % Row Count 24 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{Bloom filter: \newline - bf\_insert(item,group) \newline - bf\_contains(item,group) \newline - bf\_icontains(item,group)} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{2.32 cm} x{5.68 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Math functions}} \tn % Row 0 \SetRowColor{LightBackground} rand() & Random float number between 0 and 1 \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} srand(x) & Seeds the random number generator used by rand \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} abs(x) & Absolute value of x \tn % Row Count 5 (+ 1) % Row 3 \SetRowColor{white} floor(x) & Return int floor value of x \tn % Row Count 6 (+ 1) % Row 4 \SetRowColor{LightBackground} ceil(x) & Return int ceil value of x \tn % Row Count 7 (+ 1) % Row 5 \SetRowColor{white} round(x) & Return int round value of x \tn % Row Count 8 (+ 1) % Row 6 \SetRowColor{LightBackground} \seqsplit{fend(expression)} & Calculate by fend: \seqsplit{https://github.com/printfn/fend} \tn % Row Count 10 (+ 2) % Row 7 \SetRowColor{white} min(x,y,z) & Return min value of x, y, z \tn % Row Count 11 (+ 1) % Row 8 \SetRowColor{LightBackground} max(x,y,z) & Return max value of x, y, z \tn % Row Count 12 (+ 1) % Row 9 \SetRowColor{white} mkbool(s) & Return 0 or 1 for bool string: false, true, Y, N ... \tn % Row Count 14 (+ 2) % Row 10 \SetRowColor{LightBackground} int(s) & Convert s to int \tn % Row Count 15 (+ 1) % Row 11 \SetRowColor{white} float(s) & Convert s to float \tn % Row Count 16 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.68 cm} x{4.32 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Date/Time functions}} \tn % Row 0 \SetRowColor{LightBackground} systime() & Current unix time \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \seqsplit{strftime()/strftime(p}, timestamp) & Format timestamp by pattern \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} mktime(s) & Parse s to unix timestamp \tn % Row Count 5 (+ 2) % Row 3 \SetRowColor{white} datetime(s) & Parse s to date/time array \tn % Row Count 7 (+ 2) % Row 4 \SetRowColor{LightBackground} duration("2min + 12sec") & Parse expression to duration in seconds \tn % Row Count 9 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{strftime pattern: \seqsplit{https://docs.rs/chrono/latest/chrono/format/strftime/index.html} \newline date/time parse: \seqsplit{https://docs.rs/dateparser/latest/dateparser/\#accepted-date-formats} \newline \newline date/time array: \newline - year: 2024 \newline - month: 1, 2 \newline - monthday: 24 \newline - hour \newline - minute \newline - second \newline - yearday \newline - weekday \newline - hour: 1-24 \newline - althour: 1-12} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.92 cm} x{4.08 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{JSON/CSV/XML/HTML functions}} \tn % Row 0 \SetRowColor{LightBackground} \seqsplit{from\_json(json\_text)} & Parse json text to array \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} to\_json(arr) & Output array as json text \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} \seqsplit{json\_value(json\_text}, json\_path) & Get one text value by json path \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} \seqsplit{json\_query(json\_text}, json\_path) & Query text values by json path \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} from\_csv(line) & Parse CSV line to array \tn % Row Count 10 (+ 2) % Row 5 \SetRowColor{white} to\_csv(arr) & Output array as CSV line \tn % Row Count 12 (+ 2) % Row 6 \SetRowColor{LightBackground} \seqsplit{xml\_value(xml\_text}, xpath) & Get text value by xpath \tn % Row Count 14 (+ 2) % Row 7 \SetRowColor{white} \seqsplit{xml\_query(xml\_text}, xpath) & Query text values by xpath \tn % Row Count 16 (+ 2) % Row 8 \SetRowColor{LightBackground} \seqsplit{html\_value(html\_text}, selector) & Get text value by css selector \tn % Row Count 18 (+ 2) % Row 9 \SetRowColor{white} \seqsplit{html\_query(html\_text}, selector) & Query text values by css selector \tn % Row Count 20 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.68 cm} x{4.32 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Encode/Decode functions}} \tn % Row 0 \SetRowColor{LightBackground} encode(format, s) & Encode s with format \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} decode(format, s) & Decode s with format \tn % Row Count 2 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{Formats: \newline - hex, url, base32/58/64, base64url \newline - base64-hex, hex-base64 \newline - zlib2base64url: zlib then base64url, good for online diagram service, such as PlantUML, Kroki} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Cryto functions}} \tn % Row 0 \SetRowColor{LightBackground} digest(algorithm, s) & Digest s with algorithm \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} hmac(algorithm, secret-key, s) & hmac s with: HmacSHA256, HmacSHA512 \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} jwt("HS256", secret-key, arr-payload) & Generate JWT token: HS256, HS384, HS512 \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} dejwt(secret-key, token) & Verify JWT token and return payload array \tn % Row Count 9 (+ 3) % Row 4 \SetRowColor{LightBackground} \seqsplit{encrypt("aes-128-cbc"}, "Secret Text", "pass\_key") & Encrypt secret text \tn % Row Count 12 (+ 3) % Row 5 \SetRowColor{white} \seqsplit{decrypt("aes-128-cbc"}, "7b9c07..", "pass\_key") & Decrypt to plain text \tn % Row Count 15 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{Digest algorithm: \newline \newline - md5, sha256, sha512 \newline - bcrypt \newline - murmur3, xxh32, xxh64, blake3 \newline - crc32, adler32 \newline \newline AES algorithm: \newline - aes-128-cbc, aes-256-cbc \newline - aes-128-gcm,aes-256-gcm \newline \newline iv required gcm: encrypt("aes-128-gcm", "Secret Text", "pass\_key", "your\_iv") \newline \newline JWT algorithm \newline \newline - HS256, HS384, HS512 \newline - RS256, RS384, RS512, ES256, ES384, EdDSA: please private/public key PEM text as key \newline - JWK: for dejwt only, and key is alike \seqsplit{https://xxx.comple.com/jwks.json\#kid}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4.32 cm} x{3.68 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Network functions}} \tn % Row 0 \SetRowColor{LightBackground} http\_get(url,headers) & Return HTTP response \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} http\_post(url, headers, body) & Return HTTP response \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} send\_mail(from,to,subject,body) & Send email by REST \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} smtp\_send(url, from,to,subject,body) & Send email by SMTP \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} s3\_get(bucket, object\_name) & Return the text value of object \tn % Row Count 10 (+ 2) % Row 5 \SetRowColor{white} s3\_put(bucket, object\_name, body) & Put the text body to s3 bucket \tn % Row Count 12 (+ 2) % Row 6 \SetRowColor{LightBackground} \seqsplit{publish(nats\_mqtt\_url}, body) & Publish message to NATS \tn % Row Count 14 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{Environment variables for "send\_mail": \newline - `MLSN\_API\_KEY`: API key for MailerSend \newline \newline url for "smpt\_send": \newline - SMTP basic: `smtp://localhost:1025` \newline - SMTP + TLS \seqsplit{`smtps://user:password@host:465`} \newline \newline Environment variables for S3 access: \newline - S3\_ENDPOINT \newline - S3\_ACCESS\_KEY\_ID \newline - S3\_ACCESS\_KEY\_SECRET \newline - S3\_REGION \newline \newline url for "publish": \newline - NATS: nats://host:4222/topic \newline - MQTT: \seqsplit{mqtt://servername:1883/topic} \newline - MQTTS: \seqsplit{mqtts://token@YOUR-BROKER}.YOUR-NAMESPACE.cloudflarepubsub.com/topic} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.2 cm} x{4.8 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{KV functions}} \tn % Row 0 \SetRowColor{LightBackground} kv\_get(ns, key) & Get value by namespace and key \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} kv\_put(ns, key, value) & Put value by namespace and key \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} kv\_delete(ns, key) & Delete value by namespace and key \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} kv\_clear(ns) & Clear all keys \tn % Row Count 7 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{KV support by SQLite, Redis and NATS: \newline - SQLite: ns is normal name, such as "cluster1", "app1" \newline - Redis: ns is \seqsplit{redis://localhost:6379/0/namespace} \newline - NATS: ns is \seqsplit{nats://localhost:4222/bucket\_name}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.04 cm} x{4.96 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Color}} \tn % Row 0 \SetRowColor{LightBackground} \seqsplit{hex2rgb("\#FF0000")} & Conert hex color to RGB array \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} rgb2hex(r,g,b) & Convert RGB to hex \tn % Row Count 3 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Misc functions}} \tn % Row 0 \SetRowColor{LightBackground} var\_dump(value) & Dump and output variable to console with json format \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} \seqsplit{log\_debug(msg)/log\_info/log\_warn/log\_error} & Log s and output to console \tn % Row Count 6 (+ 3) % Row 2 \SetRowColor{LightBackground} isarray(x) & Is array or not \tn % Row Count 7 (+ 1) % Row 3 \SetRowColor{white} typeof(x) & Type name of x: array, number, string, unassigned \tn % Row Count 10 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.52 cm} x{4.48 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{References}} \tn % Row 0 \SetRowColor{LightBackground} AWK Cheat Sheet & \seqsplit{https://cheatsheets.zip/awk} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} Awk in 20 Minutes & \seqsplit{https://ferd.ca/awk-in-20-minutes.html} \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} Gawk: Effective AWK Programming & \seqsplit{https://www.gnu.org/software/gawk/manual/} \tn % Row Count 6 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}