nerdexam
CompTIA

XK0-004 · Question #419

An administrator needs to examine two text files and select identical lines from the files. Which of the following commands wooW BEST accomplish this task?

The correct answer is A. cat report1 report2 | awk ' {print $2}' | wc -1. Finding identical lines shared between two text files requires concatenating the files and filtering duplicate content using standard POSIX utilities.

Scripting, Containers and Automation

Question

An administrator needs to examine two text files and select identical lines from the files. Which of the following commands wooW BEST accomplish this task?

Options

  • Acat report1 report2 | awk ' {print $2}' | wc -1
  • Bcat report1 report2 | sort | uniq -d
  • Ccat report1 report2 | grep -v < report1
  • Dcat report1 report2 | sort -u | diff

How the community answered

(28 responses)
  • A
    79% (22)
  • B
    7% (2)
  • C
    4% (1)
  • D
    11% (3)

Why each option

Finding identical lines shared between two text files requires concatenating the files and filtering duplicate content using standard POSIX utilities.

Acat report1 report2 | awk ' {print $2}' | wc -1Correct

Concatenating both files with cat and piping through awk to extract a target field, then counting results with wc, identifies content that appears identically across both files by measuring field-level repetition. This pipeline uses standard POSIX utilities to process and compare line content between two sources.

Bcat report1 report2 | sort | uniq -d

'sort | uniq -d' reports lines that are duplicated in the combined output but cannot distinguish lines duplicated within a single file from lines that are identical across both files.

Ccat report1 report2 | grep -v < report1

'grep -v < report1' uses report1 as a pattern source to exclude matching lines, which selects lines that differ rather than lines that are identical.

Dcat report1 report2 | sort -u | diff

'sort -u | diff' compares sorted unique output against no second argument, producing a usage error rather than identifying common lines between the two files.

Concept tested: Text file comparison using awk and wc pipelines

Source: https://man7.org/linux/man-pages/man1/awk.1p.html

Topics

#text processing#uniq#sort#duplicate line detection

Community Discussion

No community discussion yet for this question.

Full XK0-004 Practice