cat print and join files

cat (short for concatenate) writes one or more files to standard output, one after another. It is the usual way to start a pipeline from a file, and the simplest way to glue files together.

Availability Preinstalled on macOS, Linux and BSD

Syntax

cat [options] [file ...]

Common options

OptionWhat it does
-nNumber every output line
-bNumber only non-blank lines
-sSqueeze runs of blank lines into one
-AShow tabs, line ends and other invisible characters (GNU). On macOS use -vet

Examples

Show a file

cat notes.txt

Join files into a new one

cat january.jsonl february.jsonl > q1.jsonl

Number lines

cat -n script.sh

Use cat with sqx

Start a query from a file

Whatever cat prints becomes the stdin table.

cat users.csv | sqx "SELECT name, plan FROM stdin LIMIT 5"

Query many JSON Lines files as one table

JSON Lines files can be joined with cat safely, because every line is a complete record.

cat logs/*.jsonl | sqx "SELECT type, COUNT(*) FROM stdin GROUP BY type"

To combine CSV files that each have a header row, see tail -n +2 on the tail page, or load each file with sqx -f.

Full documentation

This page covers the essentials. For every option, see the official documentation:

Or read the manual in your terminal: man cat