$_ CLI In Depth
Learning progress 0%
lesson text-processing regex awk

Columns: cut, paste & column

5 min read Module 6: Text Processing: grep, sed & awk Updated Dec 5, 2026
Cheat Sheet
0:00 / 3:23

Two ways to name a column

cut selects parts of each line in one of two modes. In byte or character mode, selected with -c, you name positions such as 1-3 or 5. In field mode, selected with -f, cut splits each line at a delimiter and names fields by number. The delimiter is set with -d, and it must be a single character. The default delimiter is a tab.

Field mode is the one you will use for structured text. Position mode is useful for fixed-width data such as the output of some system tools, where each column starts at the same character offset on every line.

Fields with a delimiter

A password-style file uses colons between fields. The example below builds a tiny one, then selects the first and third fields.

BASH2 lines
printf 'lice:x:1001\nbob:x:1002\n'> users.txt
cut -d: -f1,3 users.txt

The output is alice:1001 and bob:1002. The output delimiter is the same as the input delimiter, which is the default behavior. Use --output-delimiter to change it, for example to print a space or a tab between the selected fields.

Warning

cut does not collapse repeated spaces. With a space delimiter, two spaces in a row produce an empty field. For text aligned with several spaces, squeeze the spaces first with tr -s, which is covered in a later unit, or use awk.

Character positions

Position mode uses -c. A range such as 1-3 selects the first three characters, and a list such as 1,5 selects two single characters. A range that starts with a dash selects from the beginning, and one that ends with a dash selects to the end of the line.

BASH1 lines
printf '026-12-05 INFO ok\n'| cut -c1-10

This prints the date, 2026-12-05. Positions are counted in characters for the locale in use, so a line that contains multibyte characters can give a different result under different settings. For ASCII logs it is safe.

paste: joining files side by side

paste reads several files and joins their lines, one line from each file per output line, separated by a tab. It is the opposite of cut, and it is useful when two lists must be combined row by row. The -d option changes the separator, and -s joins all the lines of one file into a single line.

BASH3 lines
printf 'ed\ngreen\nblue\n'> names.txt
printf '\n2\n3\n'> codes.txt
paste -d, names.txt codes.txt

The result is three lines: red,1, green,2, and blue,3. If the files have different lengths, paste fills the shorter side with empty fields. Keep the two lists in the same order, because paste does not match rows by content. For matching by a key, use join or awk.

column: making a table readable

column is a formatting tool. With -t it arranges the input into aligned columns, splitting on whitespace by default. With -s you choose the input delimiter, so column can align a comma-separated file without you doing the padding by hand. It comes from util-linux, which is installed in the lab.

BASH1 lines
column -s, -t < table.csv

If you create a small CSV with a name column and a count column, this command prints each row with the columns padded to the widest value. The output is for people to read, not for other programs, because the padding is not a stable format. Keep the raw data in a file and align it only for display.

Choosing between cut and awk

cut is the right tool when the delimiter is a single, consistent character and you only need to select fields. It is short, fast, and easy to read in a pipeline. When the delimiter is a run of spaces, when you need to test a value before selecting it, or when you need to reorder or combine fields, awk is the better choice. The two tools answer the same question for simple inputs, so pick the one whose behavior you can predict on messy data.

A good test is to feed the tool a line with an empty field in the middle. cut returns an empty string for that field, which is what you asked for. awk with the default separator skips the extra spaces entirely, so the field numbers shift. Neither result is wrong, but the difference matters when a file was produced by a program that pads its columns. Knowing which behavior you have is what keeps a report correct.

paste has a similar split of responsibilities. It does not look at content at all. It only pairs lines by their position in each file, so it is a good way to rebuild a table from separate columns, and a poor way to join two files by a shared key. For keyed joins, the join utility or an awk program with an array lookup is the right design, and a later unit in this module shows the array approach.

Putting the tools together

A common pipeline selects a column, then aligns the result. The example below takes the first and third fields of a colon-separated file and aligns them for display.

BASH1 lines
cut -d: -f1,3 users.txt | column -s: -t

The -s: option tells column that the input is split on colons, because column -t alone splits only on whitespace and would leave these rows unchanged. The output is the same two rows as before, now aligned in two columns separated by spaces. The pattern of select, join, and align is one you will see again in the sort and awk units.

Terminal lab · 3 steps · real Linux in your browser

Extract and join columns

Select fields with cut, join files with paste, and align a table with column.

01
Select fields with a delimiter
users.txt uses colons between fields. Keep the name and the ID only: ``bash cut -d: -f1,3 users.txt > ids.txt ``
Show hint for step 1
-d sets the delimiter and -f picks fields by number.
02
Join two files side by side
names.txt and codes.txt each have three lines. Join them with a comma: ``bash paste -d, names.txt codes.txt > pairs.txt ``
Show hint for step 2
The -d option sets the separator that paste puts between the two files.
03
Align a table for reading
Take the ID table from the first step and align it with column: ``bash cut -d: -f1,3 users.txt | column -s: -t > aligned.txt ``
Show hint for step 3
column -t aligns the output into padded columns, and -s: tells it the input is split on colons.
Check yourself Question 1 of 4
Concept Check Selecting a delimiter in cut recall

Which cut option sets the field delimiter when you select fields with -f?

Recap & Key Takeaways

cut -d sets a one-character delimiter and -f picks fields by number, while -c picks character positions.
cut does not squeeze repeated delimiters, so use tr -s or awk when the input is aligned with several spaces.
paste joins files line by line, with -d for the separator and -s for joining the lines of a single file.
column -t aligns output for reading, and column -s sets the input delimiter, but its output is not meant for other programs.
Was this lesson helpful? Spot an issue or have a suggestion? Let us know on GitHub.
Report an issue