LPIC-1 Shells, Scripting and Data Management Practice Question
A script reads a CSV file where fields may contain commas within quoted strings. Which approach correctly parses such fields?
⚠ Common exam trap
Test-takers frequently assume simple field-splitting tools like 'cut' or 'read' with IFS=',' can handle CSV, but they fail to account for commas inside quoted strings, which is a classic LPIC-1 data management pitfall.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
Using awk or a dedicated tool like csvkit
CSV fields containing commas within quoted strings require a parser that understands CSV quoting rules. Awk can be scripted to handle quoted fields, and dedicated tools like csvkit (e.g., csvcut, csvformat) are designed specifically to parse CSV according to RFC 4180, correctly ignoring commas inside double-quoted strings.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Using 'cut -d',' -f1,2 file'
Why it's wrong here
cut treats every comma as a delimiter regardless of quoting, so quoted fields containing commas are split incorrectly and column positions shift. It suits fixed, unquoted delimiter files. Correct CSV parsing requires quote-aware handling, which cut does not implement.
- ✗
Using 'while IFS= read -r line; do ... done < file' and parsing manually
Why it's wrong here
Read with IFS preserves the line verbatim, but manual parsing still splits on every comma, including those inside quotes, unless you write a state machine tracking quote characters. It suits simple delimiter-free records, not CSV with embedded commas.
- ✗
Using 'while IFS=',' read -r f1 f2; do ... done < file'
Why it's wrong here
Setting IFS to a comma splits on every comma unconditionally, so a quoted field containing commas fragments into extra fields. IFS field splitting has no awareness of quoting. It works only for CSV files that never embed the delimiter inside quoted values.
- ✓
Using awk or a dedicated tool like csvkit
Why this is correct
awk handles quoted fields via FPAT or custom field-separator logic, and csvkit implements RFC 4180 quoting rules, so embedded commas inside quotes are not treated as delimiters. Simple cut or IFS-based splitting cannot distinguish quoted commas, so a quote-aware parser is required.
Go deeper
Related to this question
About these practice questions
Courseiva writes every LPIC-1 question from scratch — 402 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This LPIC-1 practice question is part of Courseiva's free LPI certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the LPIC-1 exam.