-2

I have a list of objects in column (file_column.txt) and I want to transpose this objects in row using "," as delimiter in a new file (file_row.txt).

Es.

file_column.txt:
Art
14f
adr
a24

file_row.txt:
Art,14f,adr,a24

I try to use this code:

paste -s -d " " tabella.txt

but the result it isn't right because I obtained this:

Art
,14f
,adr
,a24

Can you help me please?

2 Answers2

4

You have to use the right delimiter (comma) with the -d parameter:

cat file
Art
14f
adr
a24
paste -sd, file
Art,14f,adr,a24
thanasisp
  • 7,802
  • 2
  • 26
  • 39
0
#! /bin/bash

while read line
 do
  string="${string},${line}"
 done < file_column.txt

echo ${string#","} > file_row.txt


This works.

The while read construction is more portable as it uses only Bash syntax and the builtin read.

Asker321
  • 129
  • 1
  • 7
  • 2
    Paste is a POSIX tool, Bash is not, so the portability claim is not true (although that script does not contain any bashism). Also see [Why is using a shell loop to process text considered bad practice?](https://unix.stackexchange.com/q/169716). – Quasímodo Oct 21 '20 at 15:17
  • Well, thanks for destroying me constructively. It's always nice to learn. – Asker321 Oct 23 '20 at 22:55
  • 1
    Hey, no intention to *destroy*, only to constructively criticize ;) And I guess we have all been there as well! – Quasímodo Oct 24 '20 at 17:51