0
0
Linux CLIscripting~15 mins

cut (extract columns) in Linux CLI - Mini Project: Build & Apply

Choose your learning style9 modes available
Extract Specific Columns Using cut Command
📖 Scenario: You have a text file containing a list of employees with their details separated by commas. You want to extract only specific columns to see just the names and departments.
🎯 Goal: Learn how to use the cut command to extract specific columns from a comma-separated file.
📋 What You'll Learn
Create a file named employees.txt with exact content
Use a variable to store the delimiter
Use the cut command with the delimiter variable to extract columns
Display the extracted columns output
💡 Why This Matters
🌍 Real World
Extracting specific fields from CSV or text files is common in data processing and system administration.
💼 Career
Knowing how to use cut helps in log analysis, report generation, and quick data extraction tasks in many IT roles.
Progress0 / 4 steps
1
Create the employees.txt file
Create a file named employees.txt with the following exact content:
John,Doe,Accounting,50000
Jane,Smith,Marketing,60000
Emily,Jones,IT,55000
Linux CLI
Need a hint?

Use echo -e with newline characters \n to create multiple lines in the file.

2
Set the delimiter variable
Create a variable called DELIM and set it to a comma , to use as the delimiter.
Linux CLI
Need a hint?

Use DELIM=, to assign the comma character to the variable.

3
Extract first and third columns using cut
Use the cut command with the delimiter stored in DELIM to extract the first and third columns from employees.txt. Use -d "$DELIM" and -f 1,3 options.
Linux CLI
Need a hint?

Use cut -d "$DELIM" -f 1,3 employees.txt to extract the first and third columns.

4
Display the extracted columns output
Run the script to display the output of the cut command showing only the first and third columns.
Linux CLI
Need a hint?

The output should show only the first and third columns separated by commas.