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.
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)- A79% (22)
- B7% (2)
- C4% (1)
- D11% (3)
Why each option
Finding identical lines shared between two text files requires concatenating the files and filtering duplicate content using standard POSIX utilities.
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.
'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.
'grep -v < report1' uses report1 as a pattern source to exclude matching lines, which selects lines that differ rather than lines that are identical.
'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
Community Discussion
No community discussion yet for this question.