How can I remove a trailing newline?

Try the method rstrip() (see doc Python 2 and Python 3) Python’s rstrip() method strips all kinds of trailing whitespace by default, not just one newline as Perl does with chomp. To strip only newlines: In addition to rstrip(), there are also the methods strip() and lstrip(). Here is an example with the three of them:

What is the difference between a “line feed” and a “carriage return”?

A line feed means moving one line forward. The code is \n.A carriage return means moving the cursor to the beginning of the line. The code is \r. Windows editors often still use the combination of both as \r\n in text files. Unix uses mostly only the \n. The separation comes from typewriter times, when you turned the wheel to move the paper to … Read more

How can I remove a trailing newline?

Try the method rstrip() (see doc Python 2 and Python 3) Python’s rstrip() method strips all kinds of trailing whitespace by default, not just one newline as Perl does with chomp. To strip only newlines: In addition to rstrip(), there are also the methods strip() and lstrip(). Here is an example with the three of them:

JavaScript string newline character?

I’ve just tested a few browsers using this silly bit of JavaScript:  Run code snippetExpand snippet IE8 and Opera 9 on Windows use \r\n. All the other browsers I tested (Safari 4 and Firefox 3.5 on Windows, and Firefox 3.0 on Linux) use \n. They can all handle \n just fine when setting the value, though IE and Opera … Read more

‘\r’: command not found – .bashrc / .bash_profile [duplicate]

When all else fails in Cygwin… Try running the dos2unix command on the file in question. It might help when you see error messages like this: -bash: ‘\r’: command not found Windows style newline characters can cause issues in Cygwin. The dos2unix command modifies newline characters so they are Unix / Cygwin compatible. CAUTION: the dos2unix command modifies files in place, … Read more

‘\r’: command not found – .bashrc / .bash_profile [duplicate]

When all else fails in Cygwin… Try running the dos2unix command on the file in question. It might help when you see error messages like this: -bash: ‘\r’: command not found Windows style newline characters can cause issues in Cygwin. The dos2unix command modifies newline characters so they are Unix / Cygwin compatible. CAUTION: the dos2unix command modifies files in place, … Read more