unique

Get unique elements of an array of strings based on keys extracted from each string.

"unique" must come before a splitting such as "split" or "match".

If it finds repeated values, the first to be found is kept

Usage

z unique <separator> <key-index>

Arguments

separator Optional. The regular expression pattern to be used as a field delimiter. if not provided, z assumes the whole string is the key.
Type: pattern.
Default value: "".
key-index Optional. The index of the field that should be used as the key for determining uniqueness. if some string has less fields than the index, "" is assumed as its uniqueness key.
Type: number.
Default value: "0".

Examples

# getting the unique lines of a file
z split "\n" _ unique _ join "\n" < file.txt

# getting unique rows of a csv file based on its first column
z split "\n" _ unique "," 0 _ join "\n" < data.csv

# getting unique rows of a tsv file based on its third column
z split "\n" _ unique "\t" 3 _ join "\n" < data.tsv