line-endings

Python recognizing \r as a line delimiter

元气小坏坏 提交于 2019-12-10 23:53:26
问题 I'm using import fileinput in a Python script running on an Ubuntu box. I'm running the script on the command line with something along the lines of python myscript.py firstinputfile.txt secondinputfile.txt and inside myscript.py I am using for line in fileinput.input() to iterate over the lines. The problem I'm running into is that firstinputfile.txt and secondinputfile.txt both use Macintosh ( \r ) line endings, and fileinput.input() does not seem to be recognizing \r as a line delimiter.

Why does Python 2.7.3 think my .csv document is all on one line?

萝らか妹 提交于 2019-12-10 22:08:12
问题 I'm new to programming and I encountered a problem in some of my coursework that I can't make any sense of. Consider an imaginary file called 'example.csv' with the following contents. Key1,Value1 Key2,Value2 Key3,Value3 ... If I run the following code, it prints every line in the file followed by a single asterisk on the last line. I expected it to print each line separated by an asterisk. infile = open("example.csv", "r") for line in infile: print line.strip() print '*' #row_elements = line

Choose custom line ending for text file writing by Qt

我怕爱的太早我们不能终老 提交于 2019-12-10 19:53:04
问题 When writing a text file in Qt (using QFile and QTextStream), any \n or endl is automatically converted into the right platform specific line ending (e.g. \r\n for Windows). I would like to let the user choose which file ending is used. Is there a way to set the desired line ending in Qt without using binary file mode? 回答1: No, there isn't. The meaning of text mode is "perform line-ending changes to these of the platform". If you want to do anything else, use the binary mode, and implement

Svn non-LF line ending problems with svn:ignore on dump load

我与影子孤独终老i 提交于 2019-12-10 19:17:48
问题 I'm trying to use dump files to migrate a repository (with history intact) on a system running svn version 1.2.3 to one running 1.7.1. Since the original repository is such an early version, using svnrdump directly is not an option. I used svnadmin dump and then moved the (8 GB) dump file to the 1.7.1 system. However, when I use the svnrdump load command from there, after 231 revisions, I get the following error svnrdump: E125005: Cannot accept non-LF line endings in 'svn:ignore' property I

Can I strip carriage returns as they go into a `std::stringstream`?

非 Y 不嫁゛ 提交于 2019-12-10 17:45:16
问题 struct T { void eat(std::string const& segment) { buffer << segment; std::string sentence; while (std::getline(buffer, sentence)) std::cout << "[" << sentence.size() << "]"; } std::stringstream buffer; }; int main() { T t; t.eat("A\r\nB\nC\nD"); // ^^ ^ ^ ^ } // Actual output: [2][1][1][1] // Desired output: [1][1][1][1] I would like the std::stringstream to strip that carriage return for me (and would prefer not to have to copy and modify segment ). How might I go about this? I would have

Can SQL Server bcp in a file with Unix line endings?

余生长醉 提交于 2019-12-10 16:31:10
问题 I'm trying to use the SQL Server bcp utility to import a text file from a samba share. bcp is choking on the Unix line endings. I'm sure I could add an intermediate step, either on Unix or Windows, to change the line endings to Windows-style. But I would prefer to import the files from Unix without modification. Anybody know if there's a way to tell SQL Server bcp to look for Unix line endings? 回答1: You have to use a format file with bcp and specify the terminator as \n. The interactive

unable to solve “syntax error near unexpected token `fi'” - hidden control characters (CR) / Unicode whitespace

走远了吗. 提交于 2019-12-10 10:28:20
问题 I am new to bash scripting and i'm just trying out new things and getting to grips with it. Basically I am writing a small script to store the content of a file in a variable and then use that variable in an if statement. Through step by step i have figured out the ways to store variables and then store content of files as variables. I am now working on if statements. My test if statement if very VERY basic. I just wanted to grasp the syntax before moving onto more complicated if statement

Normalizing line endings in Visual Studio 2010

此生再无相见时 提交于 2019-12-10 01:52:00
问题 We have multiple developers working on an application and it seems that whenever one particular person works on a file then anyone else works on it they will get: The line endings in the following file are not consistent. Do you want to normalize the line endings? Is there some option in Visual Studio that we can have that developer change so we don't continually have this very irritating message pop up all the time? 回答1: If you don't want Visual Studio to check this when it opens the file,

Is there an equivalent of BufferedReader.readLine() that lets me pick what my end of line characters are?

守給你的承諾、 提交于 2019-12-10 01:47:55
问题 The Javadoc for BufferedReader.readLine() says: A line is considered to be terminated by any one of a line feed ('\n'), a carriage return ('\r'), or a carriage return followed immediately by a linefeed. I need slightly better control than this (e.g. I would like to be able to specify that an end of line is "\r\n", so that an "\n" by itself does not terminate the line). Is there any JDK or library function which does this? 回答1: Try using the Scanner class: String line = Scanner(file)

How do configure sublime to always convert to unix line endings on save?

戏子无情 提交于 2019-12-09 19:38:23
问题 I want all files that I ever save in Sublime Text to be in Unix line ending format, even when I open files that were originally saved in a different format that I later edited in Sublime? Simply setting "default_line_ending": "unix" is not enough, because that doesn't convert Windows files as I mentioned. How do I do that? 回答1: Here's a quick plugin to do the job: import sublime_plugin class SetUnixLineEndingsCommand(sublime_plugin.TextCommand): def run(self, edit): self.view.set_line_endings