Remove CR (carriage return, \r) from CRLF input.
Keep LF (\n) line breaks and write the result to standard output.
Which tr command is appropriate?
tr -d SET deletes the selected characters. Deleting CR from CRLF leaves the LF line endings.
Detailed explanation
tr '\r' '\n'Incorrect. Replacing CR with LF would add an extra line break.
Incorrect. Replacing CR with LF would add an extra line break.
tr -d '\n'Incorrect. Deleting LF would remove the line separators.
Incorrect. Deleting LF would remove the line separators.
tr -s '\r'Incorrect. -s squeezes repeated characters but does not remove CR.
Incorrect. -s squeezes repeated characters but does not remove CR.
tr -d '\r'Correct. tr -d '\r' deletes CR while preserving LF.
Correct. tr -d '\r' deletes CR while preserving LF.
Try it yourself
An example you can run in a temporary verification environment.
printf 'one\r\ntwo\r\n' | tr -d '\r' | od -An -tx1Expected result
各行末が0aだけで、0dを含まない16進列Key points
- -d means delete
- \r is CR
- \n is LF
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.