0

I can do git diff --name-only HEAD develop which gives a list of file names like this:

a.txt
b.txt
c.txt

How can I transform this to be separated by space like this:

a.txt b.txt c.txt
Peter Brittain
  • 13,489
  • 3
  • 41
  • 57
Nick Ginanto
  • 31,090
  • 47
  • 134
  • 244
  • Side note: beware of Windows (and occasionally MacOS) files with names like `files for bob.rar`. Some systems also allow newlines in file names, but spaces in file names are very common these days. – torek Apr 12 '16 at 06:57
  • Possible duplicate of [How to join multiple lines of file names into one with custom delimiter?](http://stackoverflow.com/questions/2764051/how-to-join-multiple-lines-of-file-names-into-one-with-custom-delimiter) – tripleee Jul 31 '16 at 23:16

2 Answers2

1
$ echo "a.txt
b.txt
c.txt" | paste -s -d ' '
a.txt b.txt c.txt
$

paste it serially(-s) with delimiter -d as space

or use translate tr command like this:

$ echo "a.txt
b.txt
c.txt" | tr '\n' ' '
a.txt b.txt c.txt 
riteshtch
  • 8,629
  • 4
  • 25
  • 38
1

use can use tr command to replace newline with space

echo file | tr '\n' ' '
Sandeep Sukhija
  • 1,156
  • 16
  • 30