0
0
Bash Scriptingscripting~30 mins

Processing CSV files in Bash Scripting - Mini Project: Build & Apply

Choose your learning style9 modes available
Processing CSV files
📖 Scenario: You work in a small company that keeps employee data in a CSV file. You want to write a simple script to read this file and find employees who earn more than a certain salary.
🎯 Goal: Create a bash script that reads an employee CSV file, filters employees with salary above a set threshold, and prints their names and salaries.
📋 What You'll Learn
Create a CSV file named employees.csv with exact content
Set a salary threshold variable in the script
Use a while loop with IFS=',' to read the CSV file line by line
Filter employees with salary greater than the threshold
Print the employee name and salary for those who meet the condition
💡 Why This Matters
🌍 Real World
Processing CSV files is common in many jobs to analyze data exported from spreadsheets or databases.
💼 Career
Knowing how to automate CSV data filtering with scripts helps in roles like data analyst, system administrator, and automation engineer.
Progress0 / 4 steps
1
Create the CSV file with employee data
Create a file named employees.csv with these exact lines:
name,salary
Alice,50000
Bob,60000
Charlie,45000
Diana,70000
Bash Scripting
Need a hint?

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

2
Set the salary threshold variable
In your script, create a variable called threshold and set it to 55000.
Bash Scripting
Need a hint?

Just write threshold=55000 to set the variable.

3
Read the CSV and filter employees by salary
Use a while loop with IFS=',' to read employees.csv line by line. Skip the header line. For each employee, check if their salary is greater than threshold. If yes, save their name and salary in variables.
Bash Scripting
Need a hint?

Use IFS=',' read -r name salary inside the while loop to split each line by comma.

Skip the header by checking if name is not "name".

4
Print the filtered employees' names and salaries
Inside the while loop, print the name and salary of employees whose salary is greater than threshold. The output format should be exactly: Name: Bob, Salary: 60000 for each matching employee.
Bash Scripting
Need a hint?

Use echo "Name: $name, Salary: $salary" inside the if block.