Combine the lines with the same line numbers from names.txt and scores.txt.
Print the result as comma-separated columns; no key matching is needed.
Which command is appropriate?
paste joins corresponding input lines as columns. Its -d option selects the output delimiter.
Detailed explanation
join -t, names.txt scores.txtIncorrect. join performs key-based matching rather than simple line-number pairing.
paste -d, names.txt scores.txtCorrect. paste -d, names.txt scores.txt joins corresponding lines with commas.
cat names.txt scores.txtIncorrect. cat concatenates the files vertically.
cut -d, -f1 names.txt scores.txtIncorrect. cut extracts fields from existing input and does not create a column join.
Try it yourself
An example you can run in a temporary verification environment.
tmp=$(mktemp -d); printf 'Alice\nBob\n' >"$tmp/n"; printf '80\n90\n' >"$tmp/s"; paste -d, "$tmp/n" "$tmp/s"; rm -rf "$tmp"Expected result
Alice,80
Bob,90Key points
- paste joins lines
- -d sets the delimiter
- join matches keys
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
paste aligns input lines by row number rather than matching a key.
Check the side effect
Include inputs with different line counts to observe how missing rows are handled.