I'm not really good with awk, so here what I just did to count the number occurence in one row:
the input.txt has this:
18 18 21 21 21 21 18 21
I just want to display the unique number that occur above. So, here is my code:
input="input.txt"
output=$(fmt -1 "$input" | sort | uniq | awk '{printf $1","}')
echo "$output"
The output:
18,21,
I got the result correctly but that comma , at the end, how do I remove that comma? Also, is there a simpler or a clean method without using fmt ?
The expected output:
18,21
Edit to remove comma, I use this:
sed 's/,$//'
and it's working, but is there a simpler way to do this without using fmt ?