Sort by

recency

|

197 Discussions

|

  • + 0 comments

    !/bin/bash

    read -r n read -r line

    echo "$line" | tr " " "\n" | sort | uniq -u

  • + 0 comments

    read N read m echo $m | tr ' ' '\n' > file.txt sort file.txt | uniq -u

  • + 1 comment

    tr " " "\n" | tail +2 | sort | uniq -u tr is used so each array element in new line for further processing tail is used to skip 1st line which contain total no. of array elements sort for uniq cmd to work as desired uniq -u print only the uniq element

  • + 0 comments
    read N
    readarray numbers
    printf "%s\n" ${numbers[@]} | sort -rn | uniq -u
    
  • + 0 comments
    read N
    read -a arr
    
    # We create the variable found to help us iterate
    found=0
    while [[ ${#arr[@]} -gt 1 ]]; do
        # We create an array with the existent indexes
        idx=()
        for i in ${!arr[@]}; do
            idx+=("$i")
        done
        
        # We pick the first value
        check=${arr[${idx[$found]}]}
        
        # We start the counter of matches
        count=0
        
        # We check the array counting matches
        for i in ${!arr[@]}; do
            if [[ "${arr[$i]}" -eq "$check" ]]; then
                ((count++))
            fi
        done
        
        # We check how many matches we have
        if [[ $count -eq 2 ]]; then
            # If we have 2 matcher, we delete ALL matches
            for i in ${!arr[@]}; do
                if [[ "${arr[$i]}" -eq "$check" ]]; then
                    unset arr[$i]
                fi
            done
        else
            # Else, we have 1 match, aka the lonely integer
            # We increase the found, so the check value skips the one
            ((found++))
        fi
    done
    echo "${arr[@]}"