Courseiva

LPIC-1 Shells, Scripting and Data Management Practice Question

Given a file with lines like 'John:23:Engineer', which awk command prints only the name and department (first and third fields) separated by a space?

⚠ Common exam trap

It's easy for candidates to confuse the comma (which inserts the OFS) with concatenation (no comma), leading them to pick options like C or D that produce no space between fields, or they misidentify the field numbers and select B instead of A.

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

✓

awk -F: '{print $1,$3}' file

The `-F:` flag sets the field separator to colon, and `{print $1,$3}` prints the first and third fields separated by the default output field separator (a space). This matches the requirement to output the name and department from lines like 'John:23:Engineer'.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • ✓

    awk -F: '{print $1,$3}' file

    Why this is correct

    -F: sets the input field separator to a colon, so each line splits into name, age and department. The print statement outputs $1 and $3 separated by awk's default output separator, a single space, producing the required name and department pair.

  • ✗

    awk -F: '{print $1,$2}' file

    Why it's wrong here

    $2 selects the age field, not the department, so the output pairs name with age. It is tempting because the comma-separated print list correctly inserts the output field separator, which is the right syntax for spacing; only the field number is wrong for this requirement.

  • ✗

    awk -F: '{print $1 $3}' file

    Why it's wrong here

    Omitting a separator between `$1` and `$3` concatenates them directly, producing `JohnEngineer` rather than the required space-delimited output. It is tempting because `print $1 $3` is the standard awk idiom for joining fields, and it would be correct if the task required the two values merged without any delimiter.

  • ✗

    awk -F: '{print $1 $2}' file

    Why it's wrong here

    $2 prints the age field and the missing comma concatenates name and age into 'John23'. It is tempting because it mirrors the input's first two fields, which would be correct if the file stored department second rather than third.

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 →

How Courseiva writes practice questions · Editorial policy

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.