Delete repeated rows from a file

Hi everybody:
Could anybody tell me how I can delete repeated rows from a file?, this is, for exemple I have a file like this:

0.490 958.73 281.85 6.67985 0.002481
0.490 954.833 283.991 8.73019 0.002471
0.590 950.504 286.241 6.61451 0.002461
0.690 939.323 286.112 6.16451 0.00246
0.790 928.17 285.71 5.87057 0.002451
0.890 917.196 285.503 5.6777 0.002441
0.990 906.277 284.498 5.46275 0.00244
1.090 895.529 283.818 5.43785 0.002431
1.190 884.757 283.098 5.36579 0.002421
1.290 874.22 282.2 5.33933 0.00242
1.390 863.667 281.35 5.01376 0.002411
1.490 853.3 280.55 4.61738 0.00241
1.590 842.962 279.95 4.27487 0.002401
1.690 832.775 279.362 3.77744 0.002391
1.790 822.634 278.532 3.78002 0.00239
1.890 812.608 277.625 3.98339 0.002381
1.990 802.735 276.995 4.17061 0.00238
2.090 792.845 276.65 4.77151 0.002389
..
..

in this case I only would like this:

0.490 958.73 281.85 6.67985 0.002481
0.590 950.504 286.241 6.61451 0.002461
0.690 939.323 286.112 6.16451 0.00246
0.790 928.17 285.71 5.87057 0.002451
0.890 917.196 285.503 5.6777 0.002441
0.990 906.277 284.498 5.46275 0.00244
1.090 895.529 283.818 5.43785 0.002431
1.190 884.757 283.098 5.36579 0.002421
1.290 874.22 282.2 5.33933 0.00242
1.390 863.667 281.35 5.01376 0.002411
1.490 853.3 280.55 4.61738 0.00241
1.590 842.962 279.95 4.27487 0.002401
1.690 832.775 279.362 3.77744 0.002391
1.790 822.634 278.532 3.78002 0.00239
1.890 812.608 277.625 3.98339 0.002381
1.990 802.735 276.995 4.17061 0.00238
2.090 792.845 276.65 4.77151 0.002389
..
..

Note that the pattern that it repeat is $1 and I would like the first value that appear.

Thanks a lot and cheers . :smiley:

[jsaikia] ~/prac/ $ cat file | awk '{print $1}' | sort | uniq | while read firstf; do awk '$1=="'"$firstf"'"' file | sed '1!d' ; done

0.490 958.73 281.85 6.67985 0.002481
0.590 950.504 286.241 6.61451 0.002461
0.690 939.323 286.112 6.16451 0.00246
0.790 928.17 285.71 5.87057 0.002451
0.890 917.196 285.503 5.6777 0.002441
0.990 906.277 284.498 5.46275 0.00244
1.090 895.529 283.818 5.43785 0.002431
1.190 884.757 283.098 5.36579 0.002421
1.290 874.22 282.2 5.33933 0.00242
1.390 863.667 281.35 5.01376 0.002411
1.490 853.3 280.55 4.61738 0.00241
1.590 842.962 279.95 4.27487 0.002401
1.690 832.775 279.362 3.77744 0.002391
1.790 822.634 278.532 3.78002 0.00239
1.890 812.608 277.625 3.98339 0.002381
1.990 802.735 276.995 4.17061 0.00238
2.090 792.845 276.65 4.77151 0.002389

cat Input_file|sort -ruk 1n

Ya this is really a good one, I never knew about this, thanks :slight_smile:

GNU awk:

awk '{  a[$1]=$0 } 
        END{
                n = asort(a)
                for (i=1;i<=n;i++) print a 
        }
' "file"

no need for cat

there's no need to go to such extent.

Hi all
now my script is ok.
But I have a problem.
When I run the sed command:
sed -f /tmp/delete EVDO_A12.users

Everthing that changed only display on the screen. The input file EVDO_A12.users didn't change any thing. Which problem ?

You redirect to another file, then move that file on top of the old file. Read a basic Unix book.

command oldfile>newfile; mv newfile oldfile

You can use the following

sed -id 's/old/new/g' file_name

... if your sed can do that.