shuffle

Commands ››
Parent Previous Next

The shuffle command randomly shuffles its input CSV records or fields and writes them to output.

This command can be useful when the CSV data is sorted in some way and you wants to insert into a data structure which performs better if inputs are randomised, or when you want to pick a few records at random from a file of CSV data.  

To perform a record shuffle, all file contents are read into memory. This can make the command slow or unusable for very large input files.

See also: sort

Flag

Req'd?

Description

-n count

No

Specifies number of CSV records from input to be output. This has the effect of picking count records at random (with no duplicates) from the command's input. Default is to output all input records.

-rs seed

No

Specifies random seed to use for randomising data. By default, the generator is seeded with the current date and time, which normally produces acceptable pseudo-random sequences. The seed value should be an integer.

-f fields

No

Instead of shuffling records, shuffle the specified fields in each CSV record.



The following example picks three records at random from the names.csv file:

csvfix shuffle -n 3 data/names.csv

which produces:

"George","Elliot","F"
"Jane","Austen","F"
"Oscar","Wilde","M"

Created with the Personal Edition of HelpNDoc: Full-featured multi-format Help generator