users.txt contains ID and name; scores.txt contains ID and score.
Both files are sorted by ID. Combine rows that share the first-field ID.
Which command is appropriate?
join combines sorted text files by a common field, using the first field by default.
Detailed explanation
paste users.txt scores.txtIncorrect. paste combines rows by position and does not compare IDs.
Incorrect. paste combines rows by position and does not compare IDs.
join users.txt scores.txtCorrect. join users.txt scores.txt matches the first fields of the sorted files.
Correct. join users.txt scores.txt matches the first fields of the sorted files.
cat users.txt scores.txtIncorrect. cat concatenates files vertically without matching records.
Incorrect. cat concatenates files vertically without matching records.
cut -f1 users.txt scores.txtIncorrect. cut extracts fields but does not relate records across files.
Incorrect. cut extracts fields but does not relate records across files.
Try it yourself
An example you can run in a temporary verification environment.
tmp=$(mktemp -d); printf '1 Alice\n2 Bob\n' >"$tmp/u"; printf '1 80\n2 90\n' >"$tmp/s"; join "$tmp/u" "$tmp/s"; rm -rf "$tmp"Expected result
1 Alice 80
2 Bob 90Key points
- join matches keys
- The default key is field 1
- Inputs should be sorted by the key
Notes
- Environment: GNU coreutils 9.x / 一時テキスト
- Command output formatting can vary slightly by distribution or tool version.
- Run the example in a temporary directory or process when possible.
Foundation review
Read the scope first
Check whether the command acts on the current shell, a new process, an existing process, or a file.
Verify the observable result
Use the supplied command and compare the output with the expected result.