Linux Paste Command

When working on update target field in Cassandra in batch, the IN operator is used with comma separated primary keys.

To get a list of primary keys is simple, for example, you can CAPTURE them to a text file and find them out by bash pipeline if needed, then we need to put them into a single line with comma as separator.

For example, the file test.txt conatins primary keys:

1
2
3
4
aaaaa
bbbbb
ccccc
ddddd

There are multi-way to do it, one is using paste command:

1
cat test.txt | paste -s -d, -

The output is:

1
aaaaa,bbbbb,ccccc,ddddd

Using tr command can do the same with an additional tail comma, for example:

1
2
cat test.txt | tr '\n' ','
# aaaaa,bbbbb,ccccc,ddddd,
0%