Courseiva
mediumMultiple ChoiceObjective-mapped

XK0-006 Practice Question: A Linux administrator is writing a Bash script…

A Linux administrator is writing a Bash script that needs to parse a CSV file line by line and extract the second field. Which of the following approaches is the most efficient?

⚠ Common exam trap

A common mix-up: candidates choose the `while read` loop (option A) because it seems straightforward and Bash-native, but they overlook the severe performance penalty and fragility with quoted fields, while `awk` is the correct, efficient, and robust solution for field parsing in Linux scripting exams.

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 -F',' '{print $2}'`

`awk` is purpose-built for field-based text processing; `awk -F',' '{print $2}'` efficiently splits each line by comma and prints the second field without needing an explicit loop. It handles edge cases like empty fields and large files with minimal overhead, making it the most efficient choice for CSV parsing in a script.

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 a `while read` loop with IFS=','

    Why it's wrong here

    While correct, this is less efficient than using awk, especially for large files.

  • Using `awk -F',' '{print $2}'`

    Why this is correct

    awk is designed for text processing and can handle quoted fields with proper configuration.

  • Using `cut -d, -f2`

    Why it's wrong here

    cut is efficient but cannot handle quoted fields that contain commas.

  • Using `sed` to extract the second column

    Why it's wrong here

    sed is not well-suited for column extraction; it is more for line-oriented transformations.

About these practice questions

One of 979 original XK0-006 practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This XK0-006 practice question is part of Courseiva's free CompTIA 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 XK0-006 exam.