How to Remove Columns from Text in Linux Using the colrm Command

When working with fixed-width text reports, tabular data, log dumps, or system process listings in Linux, you often need to strip away unwanted character positions from each line. While heavy-duty utilities such as awk, sed, and cut provide robust data-processing capabilities, Linux includes a specialised, lightweight utility designed solely for character-based column removal: colrm (column remove). Part of the standard util-linux package, colrm allows you to quickly truncate lines or excise specific character ranges from text streams.

What Is the colrm Command in Linux?

The colrm utility reads text from standard input (stdin) and writes the filtered result to standard output (stdout). Unlike the cut command, which requires delimiter flags or complicated syntax to select fields, colrm operates exclusively on 1-based character columns. It accepts one or two integer arguments:

  • Single Column Argument: Removes all characters starting from the specified column index through to the end of each line.
  • Two Column Arguments: Removes a specific range of characters, starting at the first column index and ending at the second column index (inclusive), preserving all characters before and after the range.

Basic Syntax of colrm

The syntax for the colrm command is clean and minimal:

colrm [start_column [stop_column]]

Because colrm reads exclusively from standard input, you feed data into it using Unix pipelines or standard file redirection operators.

How to Remove Characters from a Specified Column to the End of Line

If you have lines of text and want to truncate everything past a certain width, supply a single column number. For instance, to remove all text starting at column 25 through the end of each line in a file named audit_report.txt, run:

colrm 25 < audit_report.txt

Every character from position 25 onward is discarded, and the truncated line is printed to your terminal. This is particularly valuable for cleaning up fixed-width log files that contain excessively verbose diagnostic trailing strings.

How to Remove a Range of Columns from Text

To cut out a specific block of columns from the middle of a line while retaining the beginning and end of the line, specify both the starting and ending column positions:

colrm 10 20 < datafile.txt

In this example, characters in positions 10 through 20 (inclusive) are excised. The text from column 1 to 9 remains intact, followed immediately by the text from column 21 to the end of the line.

Piping Command Output Through colrm

One of the most practical applications of colrm is piping output from standard system monitoring utilities to declutter the display. For example, consider the output of the ls -l command, which prints file permissions, link counts, ownership, size, and timestamps:

ls -l | colrm 1 11

This command strips the first 11 columns (the permission string and spacing), instantly providing an output that begins directly with the link count and user ownership details.

Similarly, when examining running processes with ps aux, you can remove leading usernames or process IDs to focus on command paths:

ps aux | colrm 1 15

Comparing colrm with cut and awk

Understanding when to choose colrm over other Unix text filters improves command-line efficiency:

  • Use colrm: When you need the fastest, simplest method to excise fixed-width character spans without configuring field delimiters or writing filter scripts.
  • Use cut: When your data is organised by specific delimiters (such as commas, colons, or tabs) rather than fixed column coordinates.
  • Use awk: When your text processing requires complex regular expressions, variable column counts, arithmetic calculations, or conditional logic.

Saving and Redirecting colrm Output

To persist the filtered output to a new file, simply redirect standard output using the > operator:

colrm 50 < raw_access.log > cleaned_access.log

The resulting cleaned_access.log file contains the streamlined log records ready for archiving or secondary parsing.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.