Prevent wget from placing linebreaks in file titles?

2

When I run the following command:

wget http://mywebsite.com/app/count.php -O count.txt

I noticed the following:

Saving to: ‘count.txt\r’

wget is placing linebreaks into my filenames! Is there any way I can prevent this?

Thank-you for your time.

Clarity

Posted 2016-10-21T19:43:00.633

Reputation: 21

2If that wget command is in a script file, and the file has DOS-style line endings, then the carriage return will get appended to the filename. – glenn jackman – 2016-10-21T19:46:00.787

Thank-you very much! I've found a solution based off of your advice. I've changed the command format, now I'm running: wget -O "count.txt" http://mywebsite.com/app/count.php

– Clarity – 2016-10-21T19:48:59.027

2You should fix the file format instead: use dos2unix on that file. – glenn jackman – 2016-10-21T19:56:17.887

Answers

0

The issue has been resolved in comments. This answer is an extract for future users with similar problem.

Probable cause:

If that wget command is in a script file, and the file has DOS-style line endings, then the carriage return will get appended to the filename.

This is because Linux (Unix-like system in general) expects \n (another notation: LF) as a line ending. DOS and Windows use \r\n (CR+LF). This additional \r is interpreted by Linux as any normal character – as a part of the line, in this case as a part of the filename.

More information on Wikipedia.

OP's solution:

wget -O "count.txt"

It might solve this particular problem, but the additional \r is probably still there at the end, not as a part of filename though. The general, recommended solution:

You should fix the file format instead: use dos2unix on that file.

Kamil Maciorowski

Posted 2016-10-21T19:43:00.633

Reputation: 38 429