Bird
0
0

You have a file records.txt with lines like:

hard🚀 Application Q15 of 15
Bash Scripting - Text Processing in Scripts
You have a file records.txt with lines like:
John|Doe|30|Engineer
Jane|Smith|25|Designer
Bob|Brown|40|Manager

Write an awk command to print only the names (first and last) of people older than 28.
Aawk -F '|' '$3 < 28 {print $1, $2}' records.txt
Bawk -F ',' '$3 > 28 {print $1, $2}' records.txt
Cawk '{if ($3 > 28) print $1, $2}' records.txt
Dawk -F '|' '$3 > 28 {print $1, $2}' records.txt
Step-by-Step Solution
Solution:
  1. Step 1: Set correct field separator

    The file uses '|' as separator, so use -F '|' to split fields correctly.
  2. Step 2: Filter by age and print names

    Use condition $3 > 28 to select lines where age is greater than 28, then print first and second fields (first and last names).
  3. Final Answer:

    awk -F '|' '$3 > 28 {print $1, $2}' records.txt -> Option D
  4. Quick Check:

    Filter $3 > 28 and print $1, $2 [OK]
Quick Trick: Use -F '|' and condition $3 > 28 to filter [OK]
Common Mistakes:
MISTAKES
  • Using wrong field separator
  • Using wrong comparison operator
  • Not filtering before printing

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes