Вы можете сделать это на компьютере UNIX или Cygwin поверх Windows:
$ cat file
Speed, bonnie boat, like a bird on the wing,
Onward! the sailors cry;
Carry the lad that's born to be King
Over the sea to Skye.
Loud the winds howl, loud the waves roar,
Speed, bonnie boat, like a bird on the wing,
Thunderclaps rend the air;
Onward! the sailors cry;
Baffled, our foes stand by the shore,
Carry the lad that's born to be King
Follow they will not dare.
Over the sea to Skye.
.
$ cat -n file | sort -k2 -u | sort -n | cut -f2-
Speed, bonnie boat, like a bird on the wing,
Onward! the sailors cry;
Carry the lad that's born to be King
Over the sea to Skye.
Loud the winds howl, loud the waves roar,
Thunderclaps rend the air;
Baffled, our foes stand by the shore,
Follow they will not dare.
Единственная команда, приведенная выше, пытается обработать весь файл сразу:sort
и sort
предназначены для использования подкачки и т. Д., Чтобы точно обрабатывать большие файлы (см. https://unix.stackexchange.com/q/279096/133219), так что ИМХО это ваш лучший способ сделать это.
Startс помощью cat -n file
, а затем добавляйте каждую команду в конвейер по одной, чтобы увидеть, что она делает (см. ниже), но сначала просто добавьте номера строк, чтобы мы могли затем уникально отсортировать по содержимому, чтобы получить уникальные значения, а затем отсортировать поисходные номера строк, чтобы вернуть исходный порядок строк и затем удалить номера строк, которые мы добавили на первом шаге:
$ cat -n file
1 Speed, bonnie boat, like a bird on the wing,
2 Onward! the sailors cry;
3 Carry the lad that's born to be King
4 Over the sea to Skye.
5
6 Loud the winds howl, loud the waves roar,
7 Speed, bonnie boat, like a bird on the wing,
8 Thunderclaps rend the air;
9 Onward! the sailors cry;
10 Baffled, our foes stand by the shore,
11 Carry the lad that's born to be King
12 Follow they will not dare.
13 Over the sea to Skye.
14
.
$ cat -n file | sort -k2 -u
5
10 Baffled, our foes stand by the shore,
3 Carry the lad that's born to be King
12 Follow they will not dare.
6 Loud the winds howl, loud the waves roar,
2 Onward! the sailors cry;
4 Over the sea to Skye.
1 Speed, bonnie boat, like a bird on the wing,
8 Thunderclaps rend the air;
.
$ cat -n file | sort -k2 -u | sort -n
1 Speed, bonnie boat, like a bird on the wing,
2 Onward! the sailors cry;
3 Carry the lad that's born to be King
4 Over the sea to Skye.
5
6 Loud the winds howl, loud the waves roar,
8 Thunderclaps rend the air;
10 Baffled, our foes stand by the shore,
12 Follow they will not dare.
.
$ cat -n file | sort -k2 -u | sort -n | cut -f2-
Speed, bonnie boat, like a bird on the wing,
Onward! the sailors cry;
Carry the lad that's born to be King
Over the sea to Skye.
Loud the winds howl, loud the waves roar,
Thunderclaps rend the air;
Baffled, our foes stand by the shore,
Follow they will not dare.