Viewing and joining text

Much of the work at a command line is reading text — looking at a file, checking the start or end of one, pulling a column out, stitching two files together. This topic covers the commands for that: viewing files, showing parts of them, and joining or splitting text by line and by column.

This page names every command in the topic. The companion topic, Transforming text, covers the commands that reshape text — sorting, de-duplicating, substituting characters.

The commands #

Viewing a whole file

CommandPurpose
catPrint one or more files straight through — and join several into one.
tacPrint a file with its lines in reverse — last line first.
moreShow a file one screen at a time, pausing between screens.
odDump a file's raw bytes in octal, hex, decimal, or character form.

Viewing part of a file

CommandPurpose
headPrint the first lines (or bytes) of a file.
tailPrint the last lines of a file — and, with -f, keep printing as the file grows.
nlPrint a file with its lines numbered.

Cutting and combining

CommandPurpose
cutPull selected columns — byte ranges or delimited fields — out of each line.
pasteJoin files side by side, line for line.
joinJoin two files on a shared field, like a database join.
commCompare two sorted files and report which lines they share.

Splitting a file into files

CommandPurpose
splitBreak a file into equal-sized pieces.
csplitBreak a file into pieces at lines that match a pattern.

A note on input #

Almost every command here follows the same convention for where its text comes from. Name one or more files and it reads those; name none and it reads from standard input, so it can sit in the middle of a pipeline. Where a command accepts files, the name - stands for standard input, so you can mix files and piped input in one invocation.

Where to start #

To simply print a file, or join a few together, read cat — the most-used command in the topic.

Edit this page