0
0
Linux CLIscripting~20 mins

awk basics (field processing) in Linux CLI - Mini Project: Build & Apply

Choose your learning style9 modes available
awk basics (field processing)
📖 Scenario: You have a text file with information about fruits and their prices. You want to use awk to process this data and extract useful information.
🎯 Goal: Learn how to use awk to read fields from a text file and print specific columns.
📋 What You'll Learn
Use awk to process text data
Understand fields and how to access them with $1, $2, etc.
Print specific fields from each line
💡 Why This Matters
🌍 Real World
Processing text files with columns of data is common in system logs, reports, and CSV files. <code>awk</code> helps extract and manipulate this data quickly.
💼 Career
Many IT, data analysis, and system administration jobs require basic <code>awk</code> skills to automate data extraction and reporting.
Progress0 / 4 steps
1
Create the data file
Create a file named fruits.txt with these exact lines:
Apple 100
Banana 50
Cherry 75
Linux CLI
Need a hint?

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

2
Set the field separator
Write an awk command that uses space as the field separator explicitly with -F " " and reads from fruits.txt.
Linux CLI
Need a hint?

Use awk -F " " '{print $1, $2}' fruits.txt to print both fields.

3
Print only the fruit names
Modify the awk command to print only the first field (fruit name) from fruits.txt.
Linux CLI
Need a hint?

Use {print $1} to print only the first field.

4
Print fruit names with prices doubled
Write an awk command that prints the fruit name and the price multiplied by 2 from fruits.txt.
Linux CLI
Need a hint?

Use {print $1, $2 * 2} to multiply the second field by 2.