tutorials: csv - acfr/comma GitHub Wiki
group or make-blocks operation appends a block field based on the values of id fields in the input.
Append block column based using the first field as an id:
( echo "a,1,1"; echo "a,2,2"; echo "b,1,1"; ) | csv-blocks group --fields=id
Append block column using two id fields:
( echo "a,1,1"; echo "a,2,2"; echo "b,1,1"; ) | csv-blocks group --fields=id,,id
Append the an index field based on the block number, this is like a zero based count of the records in a single block, first record has index value 0.
( echo "a,1,1"; echo "a,2,2"; echo "a,3,2"; echo "b,1,1"; echo "b,2,1" ) | csv-blocks group --fields=id,,id | csv-blocks --fields=,,,block index
The same as above, however the index value is reversed, it counts down on the number of records remaining in the block.
( echo "a,1,1"; echo "a,2,2"; echo "a,3,2"; echo "b,1,1"; echo "b,2,1" ) | csv-blocks group --fields=id,,id | csv-blocks index --fields=,,,block --reverse
This is for reading a specified number of records from x number of blocks (default is 1 block) from the head of stdin.
Setting up the input data in binary.
( echo "a,1,1"; echo "a,2,2"; echo "b,1,1"; echo "c,1,1"; echo "c,2,2" ) | csv-blocks group --fields=id --from 5 | csv-blocks index --fields=,,,block --reverse | csv-to-bin 's[1],4ui' >test.bin
Opening test.bin in file descriptor 3, then run csv-blocks successively
exec 3<> test.bin
csv-blocks head --fields=,,,,index --binary 's[1],4ui' <&3 | csv-from-bin 's[1],4ui'
csv-blocks head --fields=,,,,index --binary 's[1],4ui' <&3 | csv-from-bin 's[1],4ui'
csv-blocks head --fields=,,,,index --binary 's[1],4ui' <&3 | csv-from-bin 's[1],4ui'
csv-blocks head --fields=,,,,index --binary 's[1],4ui' <&3 | csv-from-bin 's[1],4ui'
test.bin is exhausted, close the file descriptor 3
exec 3>&-