- Articles
- [7z] Compress files into a 7z archive on macOS
- [7z] Extract a 7z archive on Mac with 7z
- [7z] Install the 7z command on macOS with Homebrew
- [ack] Print only the names of matching files
- [awk] Average the second column by the value in the first
- [awk] Calculate an average
- [awk] Count fields on each line with NF
- [awk] Filter rows by the text in a column
- [awk] Join two files by a shared key
- [awk] Print a specific input line
- [awk] Print lines between two patterns
- [awk] Print text without a newline after each record
- [awk] Split a string into fields with split()
- [awk] Sum numbers from standard input
- [AWS CLI] Add multiple items to a DynamoDB table in one batch
- [AWS CLI] Check which AWS identity the CLI is using
- [AWS CLI] Download an S3 prefix with its directory name
- [AWS CLI] Generate a presigned URL for an S3 object
- [AWS CLI] Put a DynamoDB item from a JSON file
- [AWS CLI] Put an item in a DynamoDB table
- [AWS CLI] Query a DynamoDB global secondary index
- [AWS CLI] Resolve an Invalid base64 error when running aws lambda invoke
- [AWS CLI] Show only file names with aws s3 ls
- [AWS SAM] Install the AWS SAM CLI on macOS with Homebrew
- [AWS SAM] Read a value from Secrets Manager in a template
- [AWS SAM] Run a Lambda function on an EventBridge schedule
- [AWS SAM] Skip the change set confirmation during deployment
- [basename] Get the final filename component of a path
- [Bash] Capture command output in a variable
- [Bash] Check for a regular file with -f
- [Bash] Check whether a directory exists with -d
- [Bash] Detect a failure anywhere in a pipeline
- [Bash] Exit early after a command fails with set -e
- [Bash] Extract a substring by offset and length
- [Bash] Generate a UUID
- [Bash] Get the number of elements in an array
- [Bash] Loop over array elements (foreach)
- [Bash] Print an indexed array in reverse order
- [Bash] Read a file one line at a time
- [Bash] Read one line from standard input
- [Bash] Read positional command-line arguments
- [Bash] Read regular expression capture groups from BASH_REMATCH
- [Bash] Read the first element of an indexed array
- [Bash] Remove an array element with unset
- [Bash] Remove the last extension from a filename
- [Bash] Store the output of ls in an array
- [Bash] Take a range of elements from an array
- [Bash] Test for a non-empty string with if -n
- [Bash] Treat unset variables as errors with set -u
- [Bash] Write multiple lines to a file with a here document
- [BigQuery] Convert a date-time string to a TIMESTAMP
- [BigQuery] Format Unix seconds as a date and time
- [curl] Limit the time allowed for an HTTP request
- [curl] Treat an HTTP error response as a failed command
- [cut] Extract the first characters of a line
- [dirname] Get the directory portion of a path
- [Docker] Look up a container's IP address
- [find] Delete files that match a search
- [find] Exclude shallower paths with -mindepth
- [find] Find empty regular files
- [find] Find files modified after a date or time
- [find] Find files modified within the last few minutes
- [find] Limit search depth with -maxdepth
- [find] Search for files by their permission bits
- [fish] Set and export an environment variable
- [gawk] Extract text matched by a regular expression capture group
- [Git] Add a message when creating a stash
- [Git] Apply a patch created with git diff
- [Git] Apply stashed changes and keep the stash entry
- [Git] Bring another branch's changes into the current branch
- [Git] Check a diff for whitespace errors
- [Git] Cherry-pick a range of commits
- [Git] Combine search patterns with AND in git grep
- [Git] Delete a local branch with git branch -d
- [Git] Delete a specific stash entry
- [Git] Display commit history as a graph
- [Git] Download remote updates with git fetch
- [Git] Edit the latest commit message
- [Git] Fetch and integrate remote changes with git pull
- [Git] Find the root directory of the working tree
- [Git] Get the current commit hash
- [Git] List branches
- [Git] List files on a specific branch
- [Git] List the files tracked in the index
- [Git] Preview which untracked files git clean would remove
- [Git] Print only the names of files that match git grep
- [Git] Rebase a branch onto another with git rebase
- [Git] Rename a local branch with git branch -m
- [Git] Reset the current branch to match a remote branch
- [Git] Restore a file or unstage it with git restore
- [Git] Restore and remove a stash with git stash pop
- [Git] Restrict git grep to files with a particular extension
- [Git] Search a specific revision with git grep
- [Git] Send local commits to a remote with git push
- [Git] Show file status in a compact format
- [Git] Show line numbers with git grep
- [Git] Show stash diffs with git stash show -p
- [Git] Sort tags by version
- [Git] Summarize changed files and line counts with git diff --stat
- [Git] Switch back to the previously checked-out branch
- [Git] Switch branches with git switch
- [Git] Undo a commit with git revert
- [Git] Use Vim as Git's editor
- [GitHub Actions] Set a job timeout in minutes
- [GitHub Actions] Share an environment variable between steps
- [GitHub] Resize an image in an issue or pull request
- [Go] Add calendar days to a date
- [Go] Add or subtract seconds from a time.Time value
- [Go] Append an element to the end of a slice
- [Go] Assert that a slice contains a value with Testify
- [Go] Assign to a nested map without a nil map panic
- [Go] Check an expected value with Testify's assert.Equal
- [Go] Check how many times a mock method was called with Testify
- [Go] Check slice elements in any order with assert
- [Go] Check whether a map contains a key
- [Go] Check whether a string contains a substring
- [Go] Check whether a string ends with a specific suffix
- [Go] Check whether a string starts with a prefix
- [Go] Check whether a time.Time value is zero
- [Go] Check whether an interface value satisfies another interface
- [Go] Concatenate two slices with append
- [Go] Convert a string to a byte slice
- [Go] Convert a uint32 to a string
- [Go] Convert an int to an int64
- [Go] Convert an int64 to a string
- [Go] Count Unicode code points in a UTF-8 string
- [Go] Download an image from a URL and save it to a file
- [Go] Generate a presigned URL for an S3 object with aws-sdk-go
- [Go] Generate a random UUID
- [Go] Get capture groups from every regular expression match
- [Go] Get the current Unix timestamp
- [Go] Get the day of the week
- [Go] Join strings with a separator
- [Go] Load a YAML file into a struct
- [Go] Load JSON from a file into a struct
- [Go] Parse a date-time string into time.Time
- [Go] Pass parameters to a MySQL query with database/sql
- [Go] Post a message to Slack with chat.postMessage
- [Go] Prepend elements to a slice
- [Go] Read a command-line flag with the flag package
- [Go] Read a CSV file
- [Go] Read an environment variable
- [Go] Read an S3 object with the AWS SDK for Go v2
- [Go] Return different GoMock values for different arguments
- [Go] Round to the nearest integer with math.Round
- [Go] Run one test by name with go test -run
- [Go] Send a POST request with a JSON body
- [Go] Send a SigV4-signed HTTP request to API Gateway with aws-sdk-go-v2
- [Go] Send an HTTP request with Basic authentication
- [Go] Set a mock method's return value with GoMock
- [Go] Show output from passing tests with go test -v
- [Go] Sort a slice of strings alphabetically
- [Go] Split a string at a separator
- [Go] Upload a string as a text file to S3
- [Go] Use a struct as a map key
- [Go] View a time.Time in a different time zone
- [Go] Wrap a string in an io.ReadCloser
- [Go] Write CSV records to a string
- [Go] Write records to a CSV file
- [Google Apps Script] Append a row to a Google Sheet
- [Google Apps Script] Build a line chart from an array
- [Google Apps Script] Create an event in Google Calendar
- [Google Apps Script] Download an image and save it to Google Drive
- [Google Apps Script] Encode a string in Base64
- [Google Apps Script] List the events on a calendar for one day
- [Google Apps Script] Parse a CSV string
- [Google Apps Script] Parse a JSON string
- [Google Apps Script] Parse a TSV string
- [Google Apps Script] Read a web app query parameter
- [Google Apps Script] Replace the body text of a Google Doc
- [Google Apps Script] Send a POST request with a JSON body
- [Google Apps Script] Send an email with CC and BCC recipients
- [Google Apps Script] Send email with an attachment
- [Google Apps Script] Send email with MailApp
- [Google Apps Script] Upload an image to a Slack channel
- [Google Sheets] Convert a Unix timestamp to a date and time
- [grep] Exclude directories when searching recursively
- [grep] Match whole words with grep -w
- [grep] Print only text that matches a regular expression
- [grep] Print only the names of files with a match
- [grep] Search a binary file as text with grep -a
- [grep] Search a directory and its subdirectories
- [grep] Search for a literal string
- [grep] Show lines before and after a match
- [grep] Stop after a specified number of matching lines
- [Homebrew] List installed formulae
- [JavaScript] Combine arrays with concat()
- [JavaScript] Create a Date from a Unix timestamp
- [JavaScript] Get a Unix timestamp in seconds
- [JavaScript] Parse an integer from a string with parseInt()
- [JavaScript] Remove duplicate values from an array
- [jq] Base64-encode or decode a string inside JSON
- [jq] Build an object from an array of key-value entries
- [jq] Check whether at least one array element matches a condition
- [jq] Check whether every array element meets a condition
- [jq] Convert a string to a number
- [jq] Convert an object to an array of key-value entries
- [jq] Convert between ISO 8601 and Unix timestamps
- [jq] Convert JSON to CSV with @csv
- [jq] Count the elements of an array
- [jq] Exclude objects whose property contains a given string
- [jq] Extract named regular expression groups with capture
- [jq] Extract the keys of an object
- [jq] Find the first or last position of a value
- [jq] Find the minimum value in an array
- [jq] Generate a sequence of numbers with range
- [jq] Generate every combination from several arrays
- [jq] Handle conversion errors with try and catch
- [jq] Limit the number of results emitted by a filter
- [jq] Load a text file as a string with --rawfile
- [jq] Load JSON values from a file into an array with --slurpfile
- [jq] Output strings as plain text
- [jq] Parse a CSV file and convert it to JSON
- [jq] Parse a JSON string with fromjson
- [jq] Pass JSON from a shell variable with --argjson
- [jq] Print each JSON value on one line
- [jq] Read a nested value from a path with getpath
- [jq] Replace every regular expression match with gsub
- [jq] Round numbers down or up with floor and ceil
- [jq] Select objects whose field value starts with a given string
- [jq] Select objects whose property contains a given string
- [jq] Set a value at a path with setpath
- [jq] Supply a fallback for false or null
- [jq] Swap the rows and columns of a nested array
- [jq] Test whether a string matches a regular expression
- [jq] Transform each element of an array with map
- [jq] Transform nested JSON values with walk
- [jq] Turn a JSON value into a JSON string with tojson
- [jq] Use a filter result as the shell exit status
- [jq] Use if to filter objects by a condition
- [Middleman] Set the preview server port
- [MySQL] Add or subtract calendar days from a date
- [MySQL] Check the system and session time zones
- [MySQL] Convert a date and time between time zones
- [MySQL] Convert a date-time string to a Unix timestamp
- [MySQL] Convert a Unix timestamp to a date and time
- [MySQL] Convert a VARBINARY column to a string
- [MySQL] Get the current connection ID
- [MySQL] Get the current Unix timestamp
- [MySQL] Get the last day of a month
- [MySQL] Get the number of days in a given month and year
- [MySQL] Join strings with CONCAT()
- [MySQL] List tables in a specific database
- [MySQL] Parse a date-time string with STR_TO_DATE()
- [MySQL] Select the first non-NULL value with COALESCE()
- [MySQL] Write one INSERT per row with mysqldump
- [Next.js] Generate a Next.js app in the current directory
- [Node.js] Check whether a file or directory exists
- [Node.js] Create a Date object for the current time
- [Node.js] Create a directory and its subdirectory together
- [Node.js] Delete a directory synchronously
- [Node.js] Delete a single S3 object
- [Node.js] Detect a missing object error from AWS.S3.getObject (AWS SDK for JavaScript v2)
- [Node.js] Generate a version 4 UUID
- [Node.js] Invoke Lambda with AWS SDK for JavaScript v3
- [Node.js] Read an S3 object with AWS SDK for JavaScript v2
- [Node.js] Send a JSON POST request with Axios
- [npm] Install a specific version of a package
- [Oh My Fish] Find the user configuration file
- [osascript] Show a macOS notification from the command line
- [PHP] Build a query string from an array
- [PHP] Check for errors after encoding or decoding JSON
- [PHP] Count command-line arguments with $argc
- [PHP] Decode a JSON object with json_decode()
- [PHP] Encode an array or object as a JSON string
- [PHP] Escape special HTML characters
- [PHP] Filter an array with a callback
- [PHP] Format a Unix timestamp as a date string
- [PHP] Get the current Unix timestamp
- [PHP] Parse a URL query string into an array
- [PHP] Read a positional command-line argument
- [PHP] Read an environment variable
- [PHP] Read command-line options with getopt()
- [PHP] Read the IP address of the connection
- [PHP] Read the raw HTTP request body
- [PHP] Remove line breaks from a string
- [PHP] Send a POST request with a JSON body
- [PHP] Sort a nested array by one field with usort
- [PHP] Sort an array by value and preserve its keys with uasort()
- [PHP] Sort an array with usort
- [PHP] Split a URL into its components
- [PHP] Use strict comparison with in_array()
- [Python] Check the exact type of an object
- [Python] Check whether an object is an instance of a class
- [Python] Decode percent-encoded text with urllib.parse.unquote
- [Python] Extract a regular expression capture group
- [Python] Find each regular expression match and its position
- [Python] Generate a presigned URL for an S3 object with Boto3
- [Python] Iterate over indexes and values with enumerate()
- [Python] Parse named command-line options with argparse
- [Python] Percent-encode text with urllib.parse.quote
- [Python] Read command-line arguments with sys.argv
- [Python] Read query parameters from a URL
- [Python] Send an HTTP request with Basic authentication
- [Ruby] Display a DateTime with a different UTC offset
- [sed] Extract text captured by a regular expression
- [sed] Insert a line before each matching line
- [sed] Omit a particular line by number
- [sed] Print only lines where a substitution succeeds
- [sed] Reorder captured groups in a replacement
- [sed] Replace just the last occurrence on each line
- [Shell command] Align simple CSV columns in the terminal
- [Shell command] Append a comma to each line with sed
- [Shell command] Calculate a SHA-256 hash with sha256sum
- [Shell command] Check whether a TCP port accepts a connection
- [Shell command] Check whether two lists contain the same lines
- [Shell command] Convert a Unix timestamp to a date and time on Linux
- [Shell command] Convert text to lowercase with awk
- [Shell command] Convert text to uppercase with awk
- [Shell command] Convert uppercase letters to lowercase with tr
- [Shell command] Count characters with wc
- [Shell command] Create a password-protected ZIP file with zip
- [Shell command] Create a temporary file with mktemp
- [Shell command] Create missing parent directories with mkdir -p
- [Shell command] Encode and decode Base64 text
- [Shell command] Expand environment variables with envsubst
- [Shell command] Expand only specified environment variables with envsubst
- [Shell command] Extract a column from simple CSV with cut
- [Shell command] Find files by name with find
- [Shell command] Get the current Unix timestamp with date
- [Shell command] Join corresponding lines with paste
- [Shell command] Prepend text to a file's contents with echo and cat
- [Shell command] Print line breaks with echo -e in Bash
- [Shell command] Read search patterns from a file with grep
- [Shell command] Remove double quotes from a string
- [Shell command] Remove the first N characters from every line
- [Shell command] Send a POST request with curl
- [Shell command] Show a directory's total disk usage
- [Shell command] Show response headers with curl
- [Shell command] Skip the xargs command when there is no input
- [Shell command] Upload a file with curl -F
- [Shell command] Write command output to both a file and standard output
- [Slack] Add a line break to a /remind command
- [sort] Reverse the sort order
- [sort] Sort lines and keep only one of each
- [sort] Sort lines numerically with sort -n
- [sort] Sort rows using a particular column
- [sort] Sort version-like strings with sort -V
- [tail] Print only the last line
- [tar] Extract a gzip-compressed tar archive
- [tar] List the files in an archive without extracting them
- [Terraform] Print output values as JSON
- [Terraform] Skip the yes prompt when running terraform apply
- [TypeScript] Fix 'Cannot find name console' for console.log
- [TypeScript] Remove a property from a type with Omit
- [TypeScript] Run a TypeScript file with ts-node
- [TypeScript] Treat an empty object as an interface type
- [Ubuntu] Inspect a font file's family and style with fc-query
- [Ubuntu] Install a local .deb package from the command line
- [Ubuntu] List installed fonts
- [Ubuntu] See which font matches a family name with fc-match
- [uniq] Count repeated lines with uniq -c
- [vim-go] Add Go imports automatically on save
- [Vim] Show tabs and line endings with :set list
- [VS Code] Install an extension from the command line
- [VS Code] Make the code command available in fish on macOS
- [VS Code] Open a diff from the command line
- [xargs] Insert each input line into an argument
- [xargs] Read NUL-delimited filenames with xargs -0
- [zip] Create a ZIP archive from a directory
[jq] Handle conversion errors with try and catch
Created on November 30, 2026
Use try … catch … to handle errors raised by jq filters. Here tonumber converts valid numeric strings and catch null fills their unsuccessful conversions with null.
printf '%s\n' '["10","invalid","20"]' | jq 'map(try tonumber catch null)'
[
10,
null,
20
]
This preserves the input array positions, including the position of "invalid".
Skip values that cannot be converted
Omitting catch makes a failed try emit no result.
printf '%s\n' '["10","invalid","20"]' | jq 'map(try tonumber)'
[
10,
20
]
try tonumber is equivalent to try tonumber catch empty. The filter handles runtime conversion errors. Malformed input JSON fails during parsing before the filter runs.