//

CLI TOOLS REFERENCE

//
5/5 TOOLS
SECURE
$
SYNOPSIS
mlr [options] {verb} [verb-options] {input-file}
FLAGS
FLAGLONG FORMDESCRIPTION
--csvRead/write CSV format
--tsvRead/write TSV format
--json--jRead/write JSON format
--j2cJSON input, CSV output
--c2jCSV input, JSON output
--nidxNumerically indexed fields (like awk)
-IIn-place file editing
--fromSpecify input file explicitly
--fs--field-separatorSet field separator
--rs--record-separatorSet record separator
EXAMPLES
#ex-01Filter rows where age > 30
mlr --csv filter '$age > 30' data.csv
OUTPUT
name,age,city
Alice,34,Boston
Marcus,41,Denver
#ex-02Sort by field name, then age descending
mlr --csv sort -f name -r age data.csv
#ex-03Rename fields
mlr --csv rename 'first_name,name,last_name,surname' data.csv
#ex-04Convert JSON to CSV
mlr --j2c cat data.json > output.csv
#ex-05Compute stats per group
mlr --csv stats1 -a mean,min,max -f salary -g department data.csv
OUTPUT
department,salary_mean,salary_min,salary_max
Eng,112000,85000,145000
#ex-06Add computed field
mlr --csv put '$bmi = $weight / ($height ** 2)' data.csv
#ex-07Chain multiple verbs
mlr --csv filter '$active == "true"' then sort -f name then cut -f name,email data.csv
SEE ALSO:awkjqcsvkitxsv
SYNOPSIS
jq [options] <filter> [file...]
FLAGS
FLAGLONG FORMDESCRIPTION
-r--raw-outputOutput raw strings, not JSON texts
-c--compact-outputCompact output (no pretty-print)
-n--null-inputUse null as input; useful for constructing JSON
-e--exit-statusExit 1 if last output is false or null
-s--slurpRead all inputs into an array
-R--raw-inputRead each line as a string
-C--color-outputForce colorized JSON output
-f--from-fileRead filter from file
--argPass a string argument to the filter
--argjsonPass a JSON argument to the filter
EXAMPLES
#ex-01Pretty print JSON
cat data.json | jq '.'
OUTPUT
{
  "users": [...]
}
#ex-02Extract all user names
jq '.users[].name' data.json
OUTPUT
"Alice"
"Marcus"
"Priya"
#ex-03Filter array by condition
jq '[.[] | select(.active == true)]' data.json
#ex-04Transform keys to lowercase
jq 'with_entries(.key |= ascii_downcase)' data.json
#ex-05Merge two JSON files
jq -s '.[0] * .[1]' base.json override.json
#ex-06Count array elements
jq '.users | length' data.json
OUTPUT
42
#ex-07Output as CSV (raw)
jq -r '.users[] | [.name, .email, .role] | @csv' data.json
OUTPUT
"Alice","alice@corp.io","admin"
#ex-08Recursive descent — find all keys
jq '[.. | objects | keys[]] | unique' data.json
SEE ALSO:yqfxgronmlr
SYNOPSIS
grep [OPTIONS] PATTERN [FILE...]
FLAGS
FLAGLONG FORMDESCRIPTION
-r--recursiveRecursively search subdirectories
-n--line-numberPrint line number with output
-i--ignore-caseCase-insensitive matching
-v--invert-matchSelect non-matching lines
-l--files-with-matchesPrint only filenames with matches
-c--countPrint count of matching lines per file
-APrint N lines of trailing context after match
-BPrint N lines of leading context before match
-CPrint N lines of context around match
-E--extended-regexpUse extended regex (ERE)
-P--perl-regexpUse Perl-compatible regex (PCRE)
-o--only-matchingPrint only the matched part
-q--quietSuppress output; exit 0 if match found
-w--word-regexpMatch whole words only
EXAMPLES
#ex-01Basic string search
grep "error" /var/log/syslog
OUTPUT
Jun 11 04:22:18 kernel: error: device not found
#ex-02Recursive search with line numbers
grep -rn "TODO" ./src/
OUTPUT
./src/main.ts:42: // TODO: refactor this
#ex-03Invert match — exclude comment lines
grep -v "^#" /etc/ssh/sshd_config
#ex-04Case-insensitive, count per file
grep -ri -c "password" ./configs/
OUTPUT
./configs/app.conf:3
./configs/db.conf:1
#ex-05Perl regex — find IP addresses
grep -P '\b(?:\d{1,3}\.){3}\d{1,3}\b' access.log
OUTPUT
192.168.1.105 - GET /api/v2/users 200
#ex-06Context lines around match
grep -n -C 3 "CRITICAL" app.log
#ex-07Only matching text (useful with regex)
grep -oP 'user=\K[^ ]+' auth.log
OUTPUT
root
admin
deployer
#ex-08Files containing match only
grep -rl "SECRET_KEY" ./
OUTPUT
./config/secrets.py
./.env.local
#ex-09Word boundary match
grep -w "root" /etc/passwd
OUTPUT
root:x:0:0:root:/root:/bin/bash
SEE ALSO:ripgrepagacksedawk
SYNOPSIS
awk [options] 'program' [file...]
FLAGS
FLAGLONG FORMDESCRIPTION
-FSet field separator (e.g. -F: for colon)
-vAssign a variable before program executes
-fRead awk program from file
-iIn-place editing (GNU awk)
NRNumber of records (current line number)
NFNumber of fields in current record
FSField separator (default: whitespace)
OFSOutput field separator
RSRecord separator (default: newline)
ORSOutput record separator
EXAMPLES
#ex-01Print second field of each line
awk '{print $2}' file.txt
#ex-02Sum a column
awk '{sum += $3} END {print "Total:", sum}' data.txt
OUTPUT
Total: 48291
#ex-03Filter lines by field value
awk -F: '$3 == 0 {print $1}' /etc/passwd
OUTPUT
root
#ex-04Print lines between patterns
awk '/START/,/END/ {print}' logfile.txt
#ex-05Reformat CSV output
awk -F, 'NR>1 {printf "%-20s %s\n", $1, $3}' data.csv
#ex-06Count occurrences of each value
awk '{count[$1]++} END {for (k in count) print k, count[k]}' file.txt
SEE ALSO:sedgrepmlrperl
SYNOPSIS
sed [options] script [input-file...]
FLAGS
FLAGLONG FORMDESCRIPTION
-n--quietSuppress automatic printing of pattern space
-eAdd the script to commands to be executed
-fRead script from file
-iEdit files in-place (with optional backup suffix)
-r--regexp-extendedUse extended regular expressions
s/x/y/Substitute: replace x with y (first occurrence)
s/x/y/gSubstitute: replace all occurrences
dDelete matching lines
pPrint matching lines (use with -n)
a\Append text after matching line
EXAMPLES
#ex-01Replace first occurrence per line
sed 's/foo/bar/' file.txt
#ex-02Replace all occurrences, in-place
sed -i 's/old_domain/new_domain/g' config.conf
#ex-03Delete blank lines
sed '/^$/d' file.txt
#ex-04Print lines matching pattern
sed -n '/ERROR/p' app.log
#ex-05Delete lines 5 through 10
sed '5,10d' file.txt
#ex-06Insert line before match
sed '/^\[server\]/i # Auto-generated config' nginx.conf
SEE ALSO:awkgrepperltr