common/tools/sortUnique.pl
author Simon Howkins <simonh@symbian.org>
Wed, 27 Oct 2010 16:22:14 +0100
changeset 1284 0b4a09013baf
parent 246 4f2482f1dd48
permissions -rw-r--r--
Added copyright messages
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
246
4f2482f1dd48 Added sorting and removal of duplicates from TSV files.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
     1
#!perl -w
1284
0b4a09013baf Added copyright messages
Simon Howkins <simonh@symbian.org>
parents: 246
diff changeset
     2
# Copyright (c) 2009 Symbian Foundation Ltd
0b4a09013baf Added copyright messages
Simon Howkins <simonh@symbian.org>
parents: 246
diff changeset
     3
# This component and the accompanying materials are made available
0b4a09013baf Added copyright messages
Simon Howkins <simonh@symbian.org>
parents: 246
diff changeset
     4
# under the terms of the License "Eclipse Public License v1.0"
0b4a09013baf Added copyright messages
Simon Howkins <simonh@symbian.org>
parents: 246
diff changeset
     5
# which accompanies this distribution, and is available
0b4a09013baf Added copyright messages
Simon Howkins <simonh@symbian.org>
parents: 246
diff changeset
     6
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
0b4a09013baf Added copyright messages
Simon Howkins <simonh@symbian.org>
parents: 246
diff changeset
     7
#
0b4a09013baf Added copyright messages
Simon Howkins <simonh@symbian.org>
parents: 246
diff changeset
     8
# Initial Contributors:
0b4a09013baf Added copyright messages
Simon Howkins <simonh@symbian.org>
parents: 246
diff changeset
     9
# Symbian Foundation Ltd - initial contribution.
0b4a09013baf Added copyright messages
Simon Howkins <simonh@symbian.org>
parents: 246
diff changeset
    10
# 
0b4a09013baf Added copyright messages
Simon Howkins <simonh@symbian.org>
parents: 246
diff changeset
    11
# Contributors:
0b4a09013baf Added copyright messages
Simon Howkins <simonh@symbian.org>
parents: 246
diff changeset
    12
#
0b4a09013baf Added copyright messages
Simon Howkins <simonh@symbian.org>
parents: 246
diff changeset
    13
# Description:
0b4a09013baf Added copyright messages
Simon Howkins <simonh@symbian.org>
parents: 246
diff changeset
    14
# Sorts the input, removes duplicates, and outputs it
0b4a09013baf Added copyright messages
Simon Howkins <simonh@symbian.org>
parents: 246
diff changeset
    15
246
4f2482f1dd48 Added sorting and removal of duplicates from TSV files.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    16
use strict;
4f2482f1dd48 Added sorting and removal of duplicates from TSV files.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    17
4f2482f1dd48 Added sorting and removal of duplicates from TSV files.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    18
# Read it
4f2482f1dd48 Added sorting and removal of duplicates from TSV files.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    19
my @content = <>;
4f2482f1dd48 Added sorting and removal of duplicates from TSV files.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    20
4f2482f1dd48 Added sorting and removal of duplicates from TSV files.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    21
# Sort it, and grep to remove duplicates
4f2482f1dd48 Added sorting and removal of duplicates from TSV files.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    22
my $previous = "\n\n";
4f2482f1dd48 Added sorting and removal of duplicates from TSV files.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    23
@content = grep {$_ ne $previous && ($previous = $_, 1) } sort @content;
4f2482f1dd48 Added sorting and removal of duplicates from TSV files.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    24
4f2482f1dd48 Added sorting and removal of duplicates from TSV files.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    25
# Write it
4f2482f1dd48 Added sorting and removal of duplicates from TSV files.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    26
print @content;