/ factorpad.com / tech / linux-essentials / cut-command.html
An ad-free and cookie-free website.
Beginner
Learn to select sections of text at the Linux command line.
Videos can also be accessed from the Linux Essentials Playlist on YouTube.
Linux cut Command Summary with Examples (3:51)
Our thirty-third word, or command to memorize is
cut
from our category
Text.
cut
allows you to select sections from
lines of text.
-options | description |
---|---|
-b ,
--bytes=LIST |
Select using bytes specified |
-c ,
--characters=LIST |
Select using characters specified |
-f ,
--fields=LIST |
Select using fields specified |
Recall from the previous videos, we've been adding skills to help
filter potentially huge files and cut
is another tool for our arsenal.
Before we start, it helps to think of commands as mini programs and
most follow this structure:
command -option(s) argument(s)
.
The cut
command has
10 options, and the argument is our file.
Like most commands, help is available with double-dash
--help
. The command has options for
cutting bytes using -b
, characters
with -c
, and we'll use that one here.
And finally -f
for fields.
A delimiter option is available too. If you've worked with spreadsheets then this concept is familiar.
So why is cut
an important command?
Well, we're often given data sets in columnar structure and, like in a
spreadsheet, we need a way to pull out what is useful.
And now you know how to do that.
Okay, the best way to embed this in your memory is by typing in your own terminal window.
Find this on your Mac using a program called Terminal. On Linux use Terminal or Konsole, and currently Microsoft is adding this functionality to Windows.
Here we go. I started with an ls -log
command, for a list of files we've created up to this point, naming it
video33.txt
if you'd like to do the
same on your end. And we can
cat
this to view.
Next, let's cut a couple columns we're interested in, by using
characters with
cut -c 19-24, 32-42
and the argument
is video33.txt
.
And last, because we'd like to add a delimiter between the fields,
let's add the option
--output-delimiter=":"
. Then we're
good to go. And write that whole thing to a new file
video34.txt
, because we're not
done with this data.
Then cat
it if you'd like.
Okay now you know how to use cut
.
And you know the syntax for commands, options and arguments.
One last tip about the cut
command.
So we've all seen a cut
command on a
PC or a Mac, have you noticed how flexible this one is?
Okay, thanks for visiting today. I hope this was a helpful
introduction to the cut
command.
For an overview of the 100 videos, the 8 quizzes, a cheat sheet, the categories and a Q&A section, visit:
Keep the learning train moving forward. Connect at YouTube, Twitter and at our no-spam email list to stay on track.
uniq
command,
hit Back.diff
command, click Next./ factorpad.com / tech / linux-essentials / cut-command.html
A newly-updated free resource. Connect and refer a friend today.