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.
join users.txt scores.txtCorrect. 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.
cut -f1 users.txt scores.txtIncorrect. 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 / 一時テキスト
- Use small, disposable text streams when testing filters.
- Locale, encoding, and GNU/POSIX implementation details can affect edge cases.
Foundation review
Place the operation
join is record-aware: it matches fields rather than simply appending or placing columns side by side.
Check the side effect
Keep both temporary inputs sorted on the chosen key before testing.