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.
tr -d '\n'Incorrect. Deleting LF would remove the line separators.
tr -s '\r'Incorrect. -s squeezes repeated characters but does not remove CR.
tr -d '\r'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 / 標準入力
- Use small, disposable text streams when testing filters.
- Locale, encoding, and GNU/POSIX implementation details can affect edge cases.
Foundation review
Place the operation
Removing CR from CRLF input leaves LF line endings suitable for Unix text tools.
Check the side effect
Inspect the bytes before and after with a disposable sample.