You can do this with awk:
> fread("../foo.csv")
a b c d e f g h i
<int> <int> <int> <int> <int> <int> <int> <int> <int>
1: 1 2 3 4 5 6 7 8 9
2: 2 3 4 5 6 7 8 9 10
> fread("cat ../foo.csv | awk -F ',' 'BEGIN { s = 5 } { for (i=1; i<=NF; i++) printf(\"%s%s\", $(i), i<s ? OFS : i<NF ? \"\" : ORS) }'")
a b c d efghi
<int> <int> <int> <int> <int>
1: 1 2 3 4 56789
2: 2 3 4 5 678910
>
But if you canβt make it out of the battlefield with the data you are working with, I would probably use this approach. An alternative would be to concat the message after the file has been read. I am also skeptical that this will speed up work on the file.
source
share