Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using tr to replace newline with space [duplicate]

Have output from sed:

http://sitename.com/galleries/83450
72-profile

Those two strings should be merged into one and separated with space like:

http://sitename.com/galleries/83450 72-profile

Two strings are pipelined to tr in order to replace newline with space:

tr '\n' ' '

And it's not working, the result is the same as input.

Indicating space with ASCII code '\032' results in replacing \n with non-printable characters.

What's wrong? I'm using Git Bash on Windows.

like image 337
y.bregey Avatar asked Sep 13 '14 19:09

y.bregey


People also ask

How do you replace a new line character with space in Unix?

Using `sed` to replace \n with a comma By default, every line ends with \n when creating a file. The `sed` command can easily split on \n and replace the newline with any character. Another delimiter can be used in place of \n, but only when GNU sed is used.


1 Answers

Best guess is you are on windows and your line ending settings are set for windows. See this topic: How to change line-ending settings

or use:

tr '\r\n' ' '
like image 124
Garr Godfrey Avatar answered Oct 10 '22 10:10

Garr Godfrey