shuf -n 2 data.csv

Category: Data Science & Analysis

shuf -n 2 data.csv

Pick 2 random lines from a file

shuf randomizes the order of input lines, and -n 2 prints just 2 of them, a quick random sample. It is the simplest sampling tool on the command line, though it treats lines as text rather than CSV records. For header-aware sampling of a CSV, use xsv sample or mlr sample instead. Reproducible draws need --random-source pointing at a fixed file.
Looking for more? Search all 7,657 commands — works offline, in English or Spanish, and fixes typos.