0

I have an SQL command which fetches you an output like

70
138
200

This is stored in a csv and I have added headers to it but appears like

A,B,C
70
138
200

I wanted it to look like

A 70
B 138
C 200

or

A
70
B
138
C
200

or

A,B,C
70,138,200
  • Do you have a sample of the input file? – Emilio Galarraga Jan 28 '19 at 14:36
  • A,B,C 70,138,200 is the correct format you should look for. You need to change your query to get it to return 70,138,200, then add your header. – jayooin Jan 28 '19 at 14:47
  • 1
    is it possible that your SQL query has an option to include the column names as well? – Jeff Schaller Jan 28 '19 at 17:47
  • Adding the headers and doing the formatting in the SQL query seem to be the most straightforward solution here... – Kusalananda Apr 6 at 19:13
0

Assuming your original data (with no headers and with the data in a single column) is in the file called file:

$ { printf 'A\nB\nC\n'; cat file; } | paste -d, - - -
A,B,C
70,138,200

The compound command { ...; } creates the output

A
B
C
70
138
200

The paste utility reads this and organises it into three columns (the three dashes) with commas as delimiters.

Alternative formulation:

printf 'A\nB\nC\n' | cat - file | paste -d, - - -
| improve this answer | |
0

You could use paste

paste -d " " inputLetters inputNumbers

to have

A 70
B 138
C 200

The sources are

$ cat inputLetters
A
B
C

$ cat inputNumbers
70
138
200
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.