Extracting/Removing Characters by Column Positions

You can use the UNIX cut command to remove selected column positions from a list of files or a pipeline and then display the results. The –c option to cut enables you to specify a range of column positions to extract. The way to think about this command is that you are going to cut this range out of the output and keep it in the output; the rest gets thrown away, as follows:

$ date
Sun Mar 22 17:58:40 PST 1998
$ date | cut -c5-10
Mar 22
$

In the preceding example, –c510 specifies that you want to cut out and keep columns 5 through 10 and throw the rest away. You can specify more than one range, separated by a comma, as follows:

$ date | cut -c5-10,24-28
Mar 22 1998
$

Omit the ending number in ...

Get Practical UNIX now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.