As you can see from the Help information in the Uniq command, this command filters only adjacent duplicate rows.
If you want to remove all duplicate rows, you need to sort them first, or use the Uniq-u
$Uniq--Husage:Uniq[OPTION] ... [INPUT [OUTPUT]] Filter adjacent matching lines from input (or standard INPUT), writing to output (or standard output). With no options, matching lines is merged to the first occurrence. Mandatory arguments toLongOptions are mandatory for Shortoptions too. -C,--count prefix lines by the number of occurrences-D,--repeated only print duplicate lines, one forEach group-D Print all duplicate lines--all-repeated[=method] like-d, but allow separatinggroupsWith a empty line; METHOD={None (default), prepend,separate}-F,--skip-fields=N Avoid comparing the first n fields--group[=method] Show all items, separatinggroupsWith a empty line; METHOD={separate (default), Prepend,append,both}-I.,--ignore- CaseIgnore differencesinch CaseWhen comparing-S,--skip-chars=N Avoid comparing the first n characters-U,--unique only print unique lines-Z,--zero-terminated line delimiter are NUL, not newline-W,--check-chars=n Compare No Morethan N charactersinchLines--Help display this help and exit--version output version information and Exita field is a run of blanks (usually spaces and/or TABs), Thennon-blankcharacters. Fields is skipped before chars.Note: 'uniq' does not detect repeated lines unless they is adjacent. Want to sort The input first, or use 'sort-u' without 'Uni Q'. Also, comparisons honor the rules specified by 'lc_collate'.
Cat tmp.txtaaaabbbbbb cc cc AA cc catuniqaabbccaaccBB
Sort again uniq to remove all duplicates:
Cat Sort Uniq AABB cc
or use Uniq-u:
Cat uniq -UAAccBB
But this method does not necessarily work (see the example below)
$Head Info. Json-n20 | JQ. Industry |awk-F'"' '{print $}'|awk '{if (length > 0) print $}'|Uniq|Sort # ==> didn't go heavyBusiness Services Building decoration and other construction wholesale trade wholesale trade motor vehicles, electronic products and household products repair industry research and test development textile and apparel, apparel industry computer, communications and other electronic equipment manufacturing software and information technology services industry Road transport retail Trade $Head Info. Json-n20 | JQ. Industry |awk-F'"' '{print $}'|awk '{if (length > 0) print $}'|Uniq-u |Sort # ==> Go heavy not exactlyBusiness Services Building decoration and other construction industry wholesale trade motor vehicles, electronic products and household products repair industry research and test development textiles, apparel, apparel, computer, communications and other electronic equipment manufacturing software and information technology services industry Road transport retail Trade $Head Info. Json-n20 | JQ. Industry |awk-F'"' '{print $}'|awk '{if (length > 0) print $}'|Sort|Uniq # ==> to go back to successBusiness Services Building decoration and other construction industry wholesale business Research and testing of motor vehicles, electronic products and household products repair industry development of textiles, apparel, apparel, computer, communications and other electronic equipment manufacturing software and information technology Services Road transport retailing
Linux go first, sort, then uniq.