0
0
Bash Scriptingscripting~30 mins

Report generation script in Bash Scripting - Mini Project: Build & Apply

Choose your learning style9 modes available
Report generation script
📖 Scenario: You work in an office where you need to create a simple report from sales data every day. The sales data is stored in a text file with product names and sales numbers. You want to automate making a report that shows only the products with sales above a certain number.
🎯 Goal: Build a bash script that reads sales data from a file, filters products with sales above a threshold, and prints a simple report.
📋 What You'll Learn
Create a sales data file with exact product names and sales numbers
Add a variable for the sales threshold
Use a loop to read the file and select products with sales above the threshold
Print the filtered report showing product names and sales
💡 Why This Matters
🌍 Real World
Automating daily report generation from sales or other data files saves time and reduces errors.
💼 Career
Many jobs require writing scripts to process data files and create reports automatically.
Progress0 / 4 steps
1
Create the sales data file
Create a file called sales.txt with these exact lines:
Apple 50
Banana 30
Cherry 20
Date 40
Elderberry 10
Bash Scripting
Need a hint?

Use echo -e with newline characters \n to write multiple lines to sales.txt.

2
Set the sales threshold
Add a variable called threshold and set it to 25.
Bash Scripting
Need a hint?

Use threshold=25 to create the variable.

3
Filter products with sales above threshold
Use a while loop to read each line from sales.txt. Inside the loop, use if to check if the sales number is greater than threshold. If yes, add the product and sales to a variable called report with a newline after each entry.
Bash Scripting
Need a hint?

Use while read product sales; do ... done < sales.txt to read the file line by line.

Use if [ "$sales" -gt "$threshold" ] to compare numbers.

4
Print the filtered report
Print the report variable to show the products with sales above the threshold.
Bash Scripting
Need a hint?

Use printf "%b" "$report" to print the variable with newlines correctly.