IslandPatrol IslandPatrol - 1 month ago 6
Linux Question

Append to last line in bash

This question is related to this one.

The file

text.csv
contains:

#some text
some more text
b,a,c,


The file
numbers.csv
contains:

32
34
25
13


I would like to append
numbers.csv
to
text.csv
like this:

#some text
some more text
b,a,c,32,34,25,13


I have tried some of the recommendations in the linked example, but they tend to put everything on one line. I really want to append only to the last line. How can this be done?

Answer

sed and paste will solve this

$ sed '$s/$/'$(paste -sd, numbers)'/' letters

#some text
some more text
b,a,c,32,34,25,13