Removing Characters from Output with cut
Explore the cut command to efficiently remove specific characters or extract fields from command output or files. Learn to use options for character ranges, fields, and delimiters to manipulate text streams. Gain confidence in automating simple text editing tasks within the command-line interface.
We'll cover the following...
The cut command
Now, let’s discuss the cut command. The cut command lets us remove text from the output stream or a file. Let’s give it a try:
$ echo 'hello world' | cut -c 2-4
Here’s how it works. The -c flag tells the cut command to cut at characters rather than bytes. The value is 2-4, which tells cut to cut out everything other than characters 2 through 4.
We can also specify that we want everything from the beginning of the string until the specified position. For example, to grab just the first ...