92

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.

Benjamin W.
  • 46,058
  • 19
  • 106
  • 116
y.bregey
  • 1,469
  • 1
  • 12
  • 21
  • 1
    I tested piping a text file with newlines to tr with the same syntax and it works. How are you doing the pipe? Does the file have newlines AND linefeeds? maybe try "tr '\r\n' ' '" – Garr Godfrey Sep 13 '14 at 19:31
  • 2
    Why is this marked as a duplicate? The linked question specifically asked _using **sed**_, which is not what this question is about (_using **tr**_). Though the goal is the same, there may be a lot of reasons why the asker or a viewer would like to use tr and tr only. – zypA13510 Sep 16 '19 at 06:54

1 Answers1

148

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' ' '
Community
  • 1
  • 1
Garr Godfrey
  • 8,257
  • 2
  • 25
  • 23
  • 2
    agree about windows line endings. The quick fix is `dos2unix file`. Good luck to all. – shellter Sep 13 '14 at 20:46
  • well the script still has '\r'. But it doesn't look like it will work for what you want. It will put everything on one line, not just 2 lines at a time, and then your FOR loop will always go through just once. – Garr Godfrey Sep 23 '14 at 01:12