Bird
0
0

You have a file records.txt with lines like:

hard🚀 Application Q8 of 15
Bash Scripting - Text Processing in Scripts
You have a file records.txt with lines like:
id,name,age,city
1,Alice,28,NY
2,Bob,35,LA

Write an awk command to print only the name and city fields.
Aawk '{print $2, $4}' records.txt
Bawk -F: '{print $2, $4}' records.txt
Cawk -F, '{print $2, $4}' records.txt
Dawk -F, '{print $1, $3}' records.txt
Step-by-Step Solution
Solution:
  1. Step 1: Identify field separator

    The file uses commas, so set -F, to split fields by comma.
  2. Step 2: Identify fields to print

    Name is field 2, city is field 4, so print $2 and $4.
  3. Final Answer:

    awk -F, '{print $2, $4}' records.txt -> Option C
  4. Quick Check:

    Comma separator, print $2 and $4 [OK]
Quick Trick: Match -F to separator, print needed fields [OK]
Common Mistakes:
MISTAKES
  • Not setting -F for commas
  • Printing wrong fields
  • Using wrong separator

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes