O'Reilly logo

Linux and Unix Shell Programming by David Tansley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

11.5. Using cut

Cut allows you to cut columns or fields of text from text files or from standard input. When you have cut some text, you can then paste it to a text file. We’ll look at paste in the next section. The general format of cut is:

cut [options] file1 file2 

Let’s look at some of the available options.

-c list Use this to specify how many characters to cut.
-f fields Use this to specify how many fields to cut.
-d Use this to specify a different field separator, than a space or tab.

Using ‘ -c ’ you can specify ranges or parts thereof.

-c1,5-7 Means cut characters one and then five to seven.
-c1-50 Means cut the first fifty characters.

Using the ‘ -f ’ option is the same format:

-f 1,5 Means cut the fields one and five.
-f1 10-12 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required