0
0
Bash Scriptingscripting~15 mins

cut and paste in Bash Scripting - Mini Project: Build & Apply

Choose your learning style9 modes available
Extract and Combine Text Columns Using cut and paste
📖 Scenario: You work in a small office where you receive a text file with employee data. The file has names and departments separated by spaces. You want to extract the names and departments separately, then combine them side by side into a new file.
🎯 Goal: Learn how to use the cut command to extract columns from a text file and the paste command to combine columns side by side.
📋 What You'll Learn
Use cut to extract the first column (names) from employees.txt into names.txt.
Use cut to extract the second column (departments) from employees.txt into departments.txt.
Use paste to combine names.txt and departments.txt side by side into combined.txt.
Print the contents of combined.txt to the terminal.
💡 Why This Matters
🌍 Real World
Extracting and combining columns from text files is common when working with logs, reports, or CSV data in automation scripts.
💼 Career
Knowing how to manipulate text files with commands like <code>cut</code> and <code>paste</code> is useful for system administrators, data analysts, and anyone automating data processing tasks.
Progress0 / 4 steps
1
Create the initial data file
Create a file called employees.txt with these exact lines:
Alice Sales
Bob Marketing
Charlie IT
Bash Scripting
Need a hint?

Use echo with -e and redirect output to employees.txt.

2
Extract names and departments into separate files
Use cut to extract the first column (names) from employees.txt into a file called names.txt.
Then use cut to extract the second column (departments) into a file called departments.txt.
Bash Scripting
Need a hint?

Use cut -d ' ' -f1 for the first column and cut -d ' ' -f2 for the second column.

3
Combine the extracted columns side by side
Use the paste command to combine names.txt and departments.txt side by side into a new file called combined.txt.
Bash Scripting
Need a hint?

Use paste with the two filenames and redirect output to combined.txt.

4
Display the combined file
Print the contents of combined.txt to the terminal using cat.
Bash Scripting
Need a hint?

Use cat combined.txt to show the file contents.