Two questions concerning using uniq
command, please help.
First question
Say I have two files;
$ cat 1.dat
0.1 1.23
0.2 1.45
0.3 1.67
$ cat 2.dat
0.3 1.67
0.4 1.78
0.5 1.89
Using cat 1.dat 2.dat | sort -n | uniq > 3.dat
, I am able to merge two files into one. results is:
0.1 1.23
0.2 1.45
0.3 1.67
0.4 1.78
0.5 1.89
But if I have a scientific notation in 1.dat
file,
$ cat 1.dat
1e-1 1.23
0.2 1.45
0.3 1.67
the result would be:
0.2 1.45
0.3 1.67
0.4 1.78
0.5 1.89
1e-1 1.23
which is not what I want, how can I let uniq
understand 1e-1
is a number, not a string.
Second question
Same as above, but this time, let the second file 2.dat
's first row be slightly different (from 0.3 1.67
to 0.3 1.57
)
$ cat 2.dat
0.3 1.57
0.4 1.78
0.5 1.89
Then the result would be:
0.1 1.23
0.2 1.45
0.3 1.67
0.3 1.57
0.4 1.78
0.5 1.89
My question is this, how could I use uniq
just based on the value from the first file and find repetition only from the first column, so that the results is still:
0.1 1.23
0.2 1.45
0.3 1.67
0.4 1.78
0.5 1.89
Thanks
A more complex test cases
$ cat 1.dat
1e-6 -1.23
0.2 -1.45
110.7 1.55
0.3 1.67e-3