names.txt and roles.txt have the same number of lines, with corresponding data on each line.
Join each pair with a comma as name,role.
Which command is appropriate?
paste combines input files horizontally by corresponding line number. The -d option selects the output delimiter.
Detailed explanation
paste -d, names.txt roles.txtCorrect. paste joins each line pair and uses a comma between the fields.
cat names.txt roles.txtIncorrect. cat prints the second file after the first rather than joining lines.
cut -d, -f1 names.txt roles.txtIncorrect. cut selects fields; it does not combine two files line by line.
sort names.txt roles.txtIncorrect. sort orders input lines instead of pairing corresponding records.
Try it yourself
An example you can run in a temporary verification environment.
paste -d, <(printf 'alice
bob
') <(printf 'admin
viewer
')Expected result
alice,admin
bob,viewerKey points
- paste joins corresponding lines
- -d sets the delimiter
- cat concatenates vertically
Notes
- Environment: Bash 5.2 / 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.