← Back to Bash Course | Chapter 11: Process Management | Lesson 5 of 12

cut

In this page:

  1. cut

cut

cut extracts specific columns or character ranges from each line of input, using -d to set a delimiter and -f to choose fields. It's a lighter-weight alternative to awk when you only need to pull out one or two fields. cut -c extracts by character position instead of delimiter-separated fields.

Note: Use cut -d, -f2 to extract the second comma-separated field from CSV-style lines.

Example: cut

bash
#!/bin/bash
echo "alice,30,engineer" | cut -d, -f1
echo "alice,30,engineer" | cut -d, -f2,3

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.