Вы можете сделать это в следующем скрипте:
first_occurence.sh (установить его исполняемый файл)
#!/bin/bash
# Set bash to separate words by newlines only, not spaces
IFS=$'\n'
# read input
input=("$(cat)")
# get a list of unique keys - split input by space with awk for any length
unique_values=($(printf "%s\n" "${input[*]}" | awk -F' ' '{ print $1 }' | uniq))
cur=0
# check each line of input for the key
for line in ${input[@]};
do
# wildcard matching
if [[ "$line" == "${unique_values[$cur]}"* ]]
then
# print line if match, and move on to checking the next key
printf "%s\n" "$line"
cur=$((cur + 1))
fi
# break the loop if we have used up all of our unique keys (only duplicates remain)
if [ $cur -ge ${#unique_values[@]} ]
then
break
fi
done
Запустить, связав файл в: [!d2 ]
./first_occurence.sh < filename