rawiriblundell / sh_libpath

Making shell scripts more robust with libraries
Apache License 2.0
10 stars 2 forks source link

Add function to generate array from sort | uniq #5

Open rawiriblundell opened 2 years ago

rawiriblundell commented 2 years ago

It may be useful to add a function that slurps up a stream or file and returns an array e.g.

grep needle haystack | cut -d ';' -f1 | array_uniq -> slurps up stdin and puts each line into an array in the global namespace e.g. ${UNIQ[@]}

Possibly do this either sorted or unsorted, offer functions for both, or a flag to switch desired behaviour

rawiriblundell commented 2 years ago

Standard legendary awk solution: awk '!s[$0]++'

rawiriblundell commented 2 years ago

Thought:

toarray -u -> unique elements unsorted
toarray -s -> sorted
toarray -su -> sorted and unique