Remove Duplicate Line in Vim?

后端 未结 9 1170
有刺的猬
有刺的猬 2021-01-15 06:19

I\'m trying to use VIM to remove a duplicate line in an XML file I created. (I can\'t recreate the file because the ID numbers will change.)

The file looks something

9条回答
  •  青春惊慌失措
    2021-01-15 07:06

    to the OP, if you have bash 4.0

    #!/bin/bash
    # use associative array
    declare -A DUP
    file="myfile.txt"
    while read -r line
    do
        if [ -z ${DUP[$line]} ];then
            DUP[$line]=1
            echo $line >temp
        fi
    done < "$file"
    mv temp "$file"
    

提交回复
热议问题