Search code examples
arrayslinuxbashcut

linux bash cut first word from each line of a file, assign it to an array and remove duplicates


So I believe my title explains what i am trying to do. right now i am cutting and echoing out the first word which is working, all i need now is to remove duplicates... the reason i want to assign it to an array is so i can combine all the elements and create a single string of comma seperated values that i can place in a new file. maybe there is an easy way to achieve what i am trying to do. I am new to bash scripting so I appreciate any help.

thanks

here is my code so far

#!/bin/bash
cut -d' ' -f1 $1

Solution

  • cut -d' ' -f1 $1 | sort |  uniq | paste -sd,