Ubuntu 17.10 Surface Pro 3 Проблемы с курсором мыши, помощь

Вы можете сделать это в следующем скрипте:

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 
0
задан 9 November 2017 в 04:06

0 ответов

Другие вопросы по тегам:

Похожие вопросы: