Bashの一意の文字列

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)

この配列から一意のファイルをインポートする必要があります。

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

デフォルトでは、配列から重複文字列を削除する必要があります。

ベストアンサー1

あなたは試すことができます

#!/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[@]}"

出力

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

おすすめ記事