2

Does anyone know what this means?

sed -e 's/\r$//' inputfile > outputfile

This is what I have so far:

\r refers to Carriage Return (CR)

so possibly Swap the blanks for Return Carriage? in the inputfile? I'm not too sure really

2 Answers 2

2

It's changing files from CRLF-terminated lines into LF-terminated lines. The former tend to be Windows-type files where each line ends with a carriage-return/linefeed (CRLF or \r\n).

UNIX-type files just have a newline character (LF or \n).

Specifically, that sed command substitutes \r at the end of a line (indicated by $) with nothing, the same as s/xyzzy/plugh/ would change the first xyzzy in the line into plugh.

Sign up to request clarification or add additional context in comments.

Comments

2

sed is the name of the program you call.

-e tells sed that the following argument is the expression to run.

s/\r$// is a substitution: it tells sed to replace carriage return at the end of line ($) with nothing. Sed does that for each line.

inputfile is the file from which sed reads its input.

> is a redirection operator, it means the output of sed will be redirected to outputfile.

Basically, the result should be the same as dos2unix (sometimes renamed to fromdos).

2 Comments

Thank You. Do you know what the difference is with this one then? sed -e 's/$/\r/' inputfile > outputfile I would guess it tells said to replace carriage return with a blank space?
@user3576917: No. it replaces end of line ($) with a carriage return (\r). See unix2dos or todos for alternatives.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.