Skip to main content

Questions tagged [newline]

Newline refers to a character sequence representing a line break in text (also known as End of Line, EOL, or Line Break). Different operating systems have different sequences for newlines.

Filter by
Sorted by
Tagged with
3533 votes
24 answers
3.4m views

Echo newline in Bash prints literal \n

How do I print a newline? This merely prints \n: $ echo -e "Hello,\nWorld!" Hello,\nWorld!
Sergey's user avatar
  • 48.7k
2724 votes
9 answers
1.6m views

How do I break a string in YAML over multiple lines?

I have a very long string: Key: 'this is my very very very very very very long string' I would like to express it over multiple shorter lines, e.g., Key: 'this is my very very very ' + 'long ...
jjkparker's user avatar
  • 29.3k
2441 votes
12 answers
1.1m views

How to replace a character by a newline in Vim

I'm trying to replace each , in the current file by a new line: :%s/,/\n/g But it inserts what looks like a ^@ instead of an actual newline. The file is not in DOS mode or anything. What should I ...
Vinko Vrsalovic's user avatar
  • 337k
2050 votes
19 answers
412k views

Why should text files end with a newline?

I assume everyone here is familiar with the adage that all text files should end with a newline. I've known of this "rule" for years but I've always wondered — why?
Will Robertson's user avatar
2049 votes
28 answers
2.4m views

How can I remove a trailing newline?

How can I remove the last character of a string if it is a newline? "abc\n" --> "abc"
user avatar
1841 votes
2 answers
2.0m views

LF will be replaced by CRLF in git - What is that and is it important? [duplicate]

git init git add . Gives the following warnings for many files: The file will have its original line endings in your working directory. warning: LF will be replaced by CRLF in <filename>. ...
LearningRoR's user avatar
  • 27.1k
1259 votes
27 answers
1.1m views

Git replacing LF with CRLF

On a Windows machine, I added some files using git add. I got warnings saying: LF will be replaced by CRLF What are the ramifications of this conversion?
mrblah's user avatar
  • 102k
1185 votes
10 answers
1.8m views

Difference between CR LF, LF and CR line break types

I'd like to know the difference (with examples if possible) between CR LF (Windows), LF (Unix) and CR (Macintosh) line break types.
eozzy's user avatar
  • 67.9k
984 votes
26 answers
2.3m views

Writing a list to a file with Python, with newlines

How do I write a list to a file? writelines() doesn't insert newline characters, so I need to do: f.writelines([f"{line}\n" for line in lines])
Josh Arenberg's user avatar
833 votes
29 answers
704k views

Convert DOS/Windows line endings to Linux line endings in Vim

If I open files I created in Windows, the lines all end with ^M. How do I delete these characters all at once?
Bert Hekman's user avatar
  • 9,167
829 votes
12 answers
723k views

Difference between \n and \r?

What’s the difference between \n (newline) and \r (carriage return)? In particular, are there any practical differences between \n and \r? Are there places where one should be used instead of the ...
eozzy's user avatar
  • 67.9k
819 votes
11 answers
773k views

Find and replace with a newline in Visual Studio Code

I am trying out the new Microsoft Visual Studio Code editor in Linux Fedora environment. I would like to know how to replace new line (\n) in place of some other text. For example, I have html text ...
Sriram's user avatar
  • 9,224
806 votes
11 answers
1.3m views

Bash script – "/bin/bash^M: bad interpreter: No such file or directory" [duplicate]

I'm using this tutorial to learn bash scripts to automate a few tasks for me. I'm connecting to a server using putty. The script, located in .../Documents/LOG, is: #!/bin/bash # My first script echo &...
cartonn's user avatar
  • 8,284
792 votes
27 answers
1.3m views

How can I echo a newline in a batch file?

How can you you insert a newline from your batch file output? I want to do something like: echo hello\nworld Which would output: hello world
Brian R. Bondy's user avatar
759 votes
45 answers
711k views

Why do I keep getting "[eslint] Delete `CR` [prettier/prettier]"?

I am using VS Code with Prettier 1.7.2 and ESLint 1.7.0. After every newline I get: [eslint] Delete `CR` [prettier/prettier] This is the .eslintrc.json: { "extends": ["airbnb", &...
bier hier's user avatar
  • 22.1k
710 votes
13 answers
520k views

Make 'git diff' ignore ^M

In a project where some of the files contain ^M as newline separators, diffing these files is apparently impossible, since git diff sees the entire file as just a single line. How does one git diff ...
neoneye's user avatar
  • 51.6k
693 votes
9 answers
262k views

What's the strategy for handling CRLF (carriage return, line feed) with Git?

I tried committing files with CRLF-ending lines, but it failed. I spent a whole work day on my Windows computer trying different strategies and was almost drawn to stop trying to use Git and instead ...
Daniel Jomphe's user avatar
675 votes
13 answers
705k views

What are carriage return, linefeed, and form feed?

What is the meaning of the following control characters: Carriage return Line feed Form feed
ashna's user avatar
  • 7,449
670 votes
15 answers
454k views

What does the ^M character mean in Vim?

I keep getting the ^M character in my .vimrc and it breaks my configuration.
Max's user avatar
  • 6,703
652 votes
40 answers
1.1m views

How can I insert a line break into a <Text> component in React Native?

I want to insert a new line (like \r\n, <br />) in a Text component in React Native. If I have: <text> <br /> Hi~<br /> this is a test message.<br /> </text> Then ...
Curtis's user avatar
  • 6,532
629 votes
7 answers
448k views

How do I force Git to use LF instead of CR+LF under Windows?

I want to force Git to check out files under Windows using just LF not CR+LF. I checked the two configuration options, but was not able to find the right combination of settings. I want to convert all ...
sorin's user avatar
  • 167k
591 votes
8 answers
460k views

How do I get a platform-independent new line character?

How do I get a platform-independent newline in Java? I can’t use "\n" everywhere.
Spoike's user avatar
  • 121k
518 votes
15 answers
813k views

Replace a newline in TSQL

I would like to replace (or remove) a newline character in a TSQL string. Any ideas? The obvious REPLACE(@string, CHAR(13), '') just won't do it...
Peter's user avatar
  • 48.6k
506 votes
15 answers
1.4m views

What is the JavaScript string newline character?

Is \n the universal newline character sequence in JavaScript for all platforms? If not, how do I determine the character for the current environment? I'm not asking about the HTML newline element (<...
Landon Kuhn's user avatar
  • 77.7k
478 votes
12 answers
542k views

How to find out line-endings in a text file?

I'm trying to use something in bash to show me the line endings in a file printed rather than interpreted. The file is a dump from SSIS/SQL Server being read in by a Linux machine for processing. Are ...
Marco Ceppi's user avatar
  • 7,532
467 votes
21 answers
700k views

Split Java String by New Line

I'm trying to split text in a JTextArea using a regex to split the String by \n However, this does not work and I also tried by \r\n|\r|n and many other combination of regexes. Code: public void ...
dr.manhattan 's user avatar
453 votes
23 answers
639k views

How to convert DOS/Windows newline (CRLF) to Unix newline (LF)

How can I programmatically (not using vi) convert DOS/Windows newlines to Unix newlines? The dos2unix and unix2dos commands are not available on certain systems. How can I emulate them with commands ...
Koran Molovik's user avatar
452 votes
15 answers
611k views

./configure : /bin/sh^M : bad interpreter [duplicate]

I've been trying to install lpng142 on my fed 12 system. Seems like a problem to me. I get this error [root@localhost lpng142]# ./configure bash: ./configure: /bin/sh^M: bad interpreter: No such file ...
Vineeth Pradhan's user avatar
435 votes
10 answers
918k views

How do I handle newlines in JSON?

I've generated some JSON and I'm trying to pull it into an object in JavaScript. I keep getting errors. Here's what I have: var data = '{"count" : 1, "stack" : "sometext\n\n"}'; var dataObj = eval('('...
polarbear's user avatar
  • 12.8k
430 votes
19 answers
1.3m views

Writing string to a file on a new line every time

I want to append a newline to my string every time I call file.write(). What's the easiest way to do this in Python?
kaushik's user avatar
  • 5,839
415 votes
8 answers
294k views

Render a string in HTML and preserve spaces and linebreaks

I have an MVC3 app that has a details page. As part of that I have a description (retrieved from a db) that has spaces and new lines. When it is rendered the new lines and spaces are ignored by the ...
Dan dot net's user avatar
  • 6,389
414 votes
17 answers
596k views

'\r': command not found - .bashrc / .bash_profile [duplicate]

I have windows, using Cygwin, trying to set JAVA_HOME permanently through my .bashrc file. .bashrc: export PATH="$JAVA_HOME/bin:$PATH" export JAVA_HOME=$JAVA_HOME:"/cygdrive/c/Program Files (x86)/...
Jasmine's user avatar
  • 4,554
404 votes
14 answers
346k views

Pass a PHP variable to a JavaScript variable

What is the easiest way to encode a PHP string for output to a JavaScript variable? I have a PHP string which includes quotes and newlines. I need the contents of this string to be put into a ...
David Laing's user avatar
  • 7,655
364 votes
6 answers
325k views

CSV in Python adding an extra carriage return, on Windows

import csv with open('test.csv', 'w') as outfile: writer = csv.writer(outfile, delimiter=',', quoting=csv.QUOTE_MINIMAL) writer.writerow(['hi', 'dude']) writer.writerow(['hi2', 'dude2']) ...
apalopohapa's user avatar
  • 5,143
358 votes
15 answers
575k views

Removing trailing newline character from fgets() input

I am trying to get some data from the user and send it to another function in gcc. The code is something like this. printf("Enter your Name: "); if (!(fgets(Name, sizeof Name, stdin) != NULL)) { ...
sfactor's user avatar
  • 12.9k
354 votes
14 answers
164k views

How to stop vim from adding a newline at end of file?

So I work in a PHP shop, and we all use different editors, and we all have to work on Windows. I use vim, and everyone in the shop keeps complaining that whenever I edit a file there is a newline at ...
Boushley's user avatar
  • 6,956
339 votes
9 answers
378k views

Bash: Strip trailing linebreak from output

When I execute commands in Bash (or to be specific, wc -l < log.txt), the output contains a linebreak after it. How do I get rid of it?
hexacyanide's user avatar
  • 90.4k
323 votes
7 answers
187k views

Visual Studio Code — Insert Newline at the End of Files

When saving a file using Visual Studio Code, a newline is not automatically added to the end of the file, causing all sorts of potential issues. How can I append a newline automatically in Visual ...
LJH's user avatar
  • 8,404
312 votes
17 answers
739k views

How to remove line breaks from a file in Java?

How can I replace all line breaks from a string in Java in such a way that will work on Windows and Linux (ie no OS specific problems of carriage return/line feed/new line etc.)? I've tried (note ...
tree-hacker's user avatar
  • 5,441
298 votes
4 answers
386k views

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

If there are two keywords then they must have their own meanings. So I want to know what makes them different and what their code is.
pheromix's user avatar
  • 18.9k
296 votes
20 answers
337k views

Windows batch: echo without new line

What is the Windows batch equivalent of the Linux shell command echo -n which suppresses the newline at the end of the output? The idea is to write on the same line inside a loop.
gregseth's user avatar
  • 13.2k
294 votes
8 answers
148k views

How line ending conversions work with git core.autocrlf between different operating systems

I've read a lot of different questions and answers on Stack Overflow as well as git documentation on how the core.autocrlf setting works. This is my understanding from what I've read: Unix and Mac OSX ...
Michael Maddox's user avatar
291 votes
21 answers
316k views

How to add line break for UILabel?

Let see that I have a string look like this: NSString *longStr = @"AAAAA\nBBBBB\nCCCCC"; How do I make it so that the UILabel display the message like this AAAAA BBBBB CCCCC I don't ...
Thang Pham's user avatar
  • 38.6k
288 votes
9 answers
83k views

Trying to fix line-endings with git filter-branch, but having no luck

I have been bitten by the Windows/Linux line-ending issue with git. It seems, via GitHub, MSysGit, and other sources, that the best solution is to have your local repos set to use linux-style line ...
Brian Donahue's user avatar
273 votes
32 answers
430k views

How do I add a newline to a TextView in Android?

When I define a TextView in xml, how do I add a new line to it? \n seems not to work. <TextView android:id="@+id/txtTitlevalue" android:text="Line1 -\nLine2" android:...
Pentium10's user avatar
  • 207k
254 votes
8 answers
224k views

How can I use newline '\n' in an f-string to format output?

I tried this code: names = ['Adam', 'Bob', 'Cyril'] text = f"Winners are:\n{'\n'.join(names)}" print(text) However, '\' cannot be used inside the {...} expression portions of an f-string. ...
malmed's user avatar
  • 2,848
252 votes
9 answers
432k views

See line breaks and carriage returns in editor

Is there a text editor on Linux that allows me to see line breaks and carriage returns? Does Vim support this feature?
usertest's user avatar
  • 27.4k
249 votes
18 answers
377k views

Remove blank lines with grep

I tried grep -v '^$' in Linux and that didn't work. This file came from a Windows file system.
node ninja's user avatar
  • 32.7k
239 votes
3 answers
372k views

How to prevent that CR and LF are changed when writing bytes to file?

I have a function that returns a string. The string contains carriage returns and newlines (0x0D, 0x0A). However when I write to a file it contains only the new line feeds. Is there a way to get the ...
Blackninja543's user avatar
232 votes
26 answers
336k views

Add line break within tooltips

How can line breaks be added within a HTML tooltip? I tried using <br/> and \n within the tooltip as follows: <a href="#" title="Some long text <br/> Second line text \n Third line ...
Aakash Chakravarthy's user avatar

1
2 3 4 5
103