Bird
0
0

Given a CSV file data.csv with content:

medium📝 Command Output Q13 of 15
Bash Scripting - File Operations in Scripts
Given a CSV file data.csv with content:
name,age,city
Alice,30,New York
Bob,25,Los Angeles
Carol,27,Chicago

What is the output of the command awk -F, '$2 > 26 {print $1}' data.csv?
AAlice
BAlice Bob Carol
CBob Carol
DAlice Carol
Step-by-Step Solution
Solution:
  1. Step 1: Understand the awk condition and field separator

    The command uses -F, to split fields by commas. The condition $2 > 26 filters rows where the second field (age) is greater than 26.
  2. Step 2: Apply the condition to each row

    Rows:
    - Header: 'age' > 26? No (string)
    - Alice,30: 30 > 26? Yes, print $1 = Alice
    - Bob,25: 25 > 26? No
    - Carol,27: 27 > 26? Yes, print $1 = Carol
  3. Final Answer:

    Alice Carol -> Option D
  4. Quick Check:

    Filter ages > 26, print names [OK]
Quick Trick: Filter with $column condition and print desired field [OK]
Common Mistakes:
MISTAKES
  • Including header row in output
  • Confusing field numbers
  • Not using correct field separator

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes