Skip to end of metadata
Go to start of metadata

If you have csv records with multiple keys and would like to assign unique ids to those records, you could use csv-enumerate. (In particular, it would help to overcome the current limitation of csv-calc, which cannot handle multiple id fields.)

csv-enumerate appends id to the input string.

For example:

> ( echo 20170101T000000,hello ; echo 20170101T000000,world ; echo 20170101T000001,hello ; echo 20170101T000000,world ) | csv-enumerate --fields ,greeting
20170101T000000,hello,0
20170101T000000,world,1
20170101T000001,hello,0
20170101T000000,world,1
 
> ( echo 20170101T000000,hello ; echo 20170101T000000,world ; echo 20170101T000001,hello ; echo 20170101T000000,world ) | csv-enumerate --fields t,greeting
20170101T000000,hello,0
20170101T000000,world,1
20170101T000001,hello,2
20170101T000000,world,1

You also can output a list of all values, their ids, and number of entries with given ids, e.g:

> ( echo 20170101T000000,hello ; echo 20170101T000000,world ; echo 20170101T000001,hello ; echo 20170101T000000,world ; echo 20170101T000005,world ) | csv-enumerate --fields ,greeting --map
"world",1,3
"hello",0,2

Binary mode is supported as usual.

  • No labels