end-of-line

How to remove ^M

谁说我不能喝 提交于 2019-12-18 05:48:28
问题 How can I remove the ^M character from a text file (at the end of line) in a Python script? I did the following, and there are ^M at every line-break. file = open(filename, "w") file.write(something) 回答1: If you're writing the file, you should specify open(filename, "wb") . That way, you'll be writing in binary mode, and Python won't attempt to determine the correct newlines for the system you're on. 回答2: Python can open a file in binary mode or in text mode. Text is the default, so a mode of

Incomplete final line when trying to read csv in R

你离开我真会死。 提交于 2019-12-12 13:18:38
问题 I've got R v.2.15.1 running on Mac OS 10.8.2 . Earlier today, R started throwing errors at me every time I try to import ANY recently created (today) csv files. Older (before today) csv files work fine, but anything I create that's new will not read in without a warning. I'm creating the csv's the same way -- saving the spreadsheet as .csv in MS Excel (Office for Mac 2011). Even with a dummy file ('test.csv'), I get this: "Warning message: In read.table(file = file, header = header, sep = sep

Inserting endline into a stringstream

心不动则不痛 提交于 2019-12-10 14:14:54
问题 We know that when inserting \n in a file stream, the appropriate end-of-line sequence for the system will be written to the file (e.g. \r\n for Windows). Does inserting an endline in a std::stringstream result in the system-appropriate end-of-line sequence being written to the string? For example: #include <sstream> int main() { std::ostringstream oss; oss << std::endl; std::string endlineSequence = oss.str(); bool isWindows = enlineSequence == "\r\n"; bool isOldMac = endlineSequence == "\r";

Regex: Match the text before the end of line

心已入冬 提交于 2019-12-10 11:47:58
问题 I have a file that looks like this: J6 INT-00113G 227.905 5.994 180 ~!@#$%&^) J3 INT-00113G 227.905 -203.244 180 12341341312315 U13 EXCLUDES -42.210 181.294 180 QFP128 U3 IC-00276G 5.135 198.644 90 B%GA!@-48 U12 IC-00270G -123.610 -201.594 0 SOP8_000 J1 INT-00112G 269.665 179.894 180 SOIC16_1 J2 INT-00112G 269.665 198.144 180 SOIC16-_2 .. .......... ....... ....... ... ................ And I would like to match the end value in the 6th column in order to remove it from a list. The length of

how to check end-of-line of a text file to see if it is unix or dos format?

风格不统一 提交于 2019-12-06 03:37:44
问题 I need to convert the text file to dos format (ending each line with 0x0d0x0a , rather than 0x0a only), if the file is in unix format ( 0x0a only at the end of each line). I know how to convert it ( sed 's/$/^M/' ), but don't how how to detect the end-of-line character(s) of a file. I am using ksh. Any help would be appreciated. [Update]: Kind of figured it out, and here is my ksh script to do the check. [qiangxu@host:/my/folder]# cat eol_check.ksh #!/usr/bin/ksh if ! head -1 $1 |grep ^M$ >

NSAttributedString '\\n' ignored

落花浮王杯 提交于 2019-12-04 23:09:39
I have a single view whose only UI element is a UITextView . In viewDidLoad: I create an attributed string with "Text\n" and set the text view's attributed text as such: NSAttributedString *string = [[NSAttributedString alloc] initWithString:@"Text\n"]; [self.textView setAttributedText:string]; My problem is that the line break is ignored when I run the app. If I use an NSString and setText: that doesn't happen. NSString *string = [[NSString alloc] initWithString:@"Text\n"]; [self.textView setText:string]; Can anyone shed some light on what is happening? I can't seem to find anything in

how to check end-of-line of a text file to see if it is unix or dos format?

强颜欢笑 提交于 2019-12-04 08:26:44
I need to convert the text file to dos format (ending each line with 0x0d0x0a , rather than 0x0a only), if the file is in unix format ( 0x0a only at the end of each line). I know how to convert it ( sed 's/$/^M/' ), but don't how how to detect the end-of-line character(s) of a file. I am using ksh. Any help would be appreciated. [Update]: Kind of figured it out, and here is my ksh script to do the check. [qiangxu@host:/my/folder]# cat eol_check.ksh #!/usr/bin/ksh if ! head -1 $1 |grep ^M$ >/dev/null 2>&1; then echo UNIX else echo DOS fi In the above script, ^M should be inserted in vi with

Configure Visual Studio to use UNIX line endings

淺唱寂寞╮ 提交于 2019-12-03 04:41:11
问题 We would like to use Visual Studio 2005 to work on a local copy of an SVN repository. This local copy has been checked out by Mac OS X (and updates and commits will only be made under Mac OS X, so no problem there), and as a consequence the line endings are UNIX-style. We fear that Visual Studio will introduce Windows-style line endings. Is it possible to force Visual Studio to use UNIX line endings? 回答1: As OP states "File > Advanced Save Options", select Unix Line Endings. 回答2: Here are

Vim no end of line on last line or eof

自作多情 提交于 2019-12-02 18:34:05
I am trying to setup vim to skip adding eol on last line or eof, i have tried this :set binary :set noeol :w which is not perfect cause binary override filetype for later use. Any other option to set this, i don't need newline on last line. I wanted to add an answer that I think can be as useful. The selected answer always remove the EOL on files even if they had one to begin with. This may be the behavior that you want, it also may not be. In my opinion I want to preserve the EOL as I originally opened the file. What I suggest is a slight modification. Put set binary at the top of your .vimrc

Delete last line break using sed [duplicate]

旧时模样 提交于 2019-12-02 05:42:02
问题 This question already has answers here : How can I delete a newline if it is the last character in a file? (22 answers) Closed last year . How to delete the last \n from a file. The file has a last blank line created for a line break in the last text line. I'm using this command: sed '/^\s*$/d' But that las blank line is not removed. 回答1: Why is sed printing a newline? When you read the sed POSIX standard, then it states: Whenever the pattern space is written to standard output or a named