Bird
0
0

Which bash command is best to print only the first column from a CSV file named records.csv?

easy🧠 Conceptual Q2 of 15
Bash Scripting - File Operations in Scripts
Which bash command is best to print only the first column from a CSV file named records.csv?
Aawk -F',' '{print $1}' records.csv
Bcut -f1 records.csv
Cgrep -o '^[^,]*' records.csv
Dsed 's/,.*//' records.csv
Step-by-Step Solution
Solution:
  1. Step 1: Identify command to split by comma

    awk with -F',' splits lines by commas, allowing column selection.
  2. Step 2: Check each option's behavior

    awk -F',' '{print $1}' records.csv prints first column correctly; cut without -d won't split by comma; grep and sed are less direct or may fail on complex lines.
  3. Final Answer:

    awk -F',' '{print $1}' records.csv -> Option A
  4. Quick Check:

    awk -F',' prints columns by comma [OK]
Quick Trick: Use awk -F',' to select CSV columns easily [OK]
Common Mistakes:
MISTAKES
  • Using cut without specifying delimiter
  • Assuming grep extracts columns
  • Using sed without proper regex for CSV

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes