0

I have an array

array=(src/ucode/pkgs/get_ch.c  qa/tests/ucode/chktest.pl  src/ucode/pkgs/get_ch.c src/profile/settings.txt  src/ucode/pkgs/main_pf.c  src/ucode/pkgs/get_ch.c src/ucode/pkgs/main_ch.c src/ucode/pkgs/main_pf.c)

I need to get unique files from that array

src/ucode/pkgs/get_ch.c  qa/tests/ucode/chktest.pl src/profile/settings.txt  src/ucode/pkgs/main_pf.c  src/ucode/pkgs/main_ch.c

Basically I need to delete duplicate strings from the array

Eric Renouf
  • 18,431
tony
  • 61
  • 3

1 Answers1

0

you could try

#!/bin/bash

array=(src/ucode/pkgs/get_ch.c
qa/tests/ucode/chktest.pl
src/ucode/pkgs/get_ch.c
src/profile/settings.txt
src/ucode/pkgs/main_pf.c
src/ucode/pkgs/get_ch.c
src/ucode/pkgs/main_ch.c
src/ucode/pkgs/main_pf.c)

sorted_array=( $(printf "%s\n" "${array[@]}" | sort | uniq) )

# dump the sorted array to check its contents
printf "%s\n" "${sorted_array[@]}"

output

qa/tests/ucode/chktest.pl
src/profile/settings.txt
src/ucode/pkgs/get_ch.c
src/ucode/pkgs/main_ch.c
src/ucode/pkgs/main_pf.c