-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Saturday 15 March 2003 07:11 pm, Youichi Mano wrote:
> Hi all,
>
> I want to "uniq" by comparing the specified column for matrix data.
> I want to realize this operation by command line programs ,
> not any script file.
>
> For example , if the following data is operated by first column uniq,
> -------------------------
> 1 eagle 197
> 1 bird 387
> 2 camera 91
> 2 dog 62
> 3 apple 89
> -------------------------
>
> the output will be
>
> -------------------------
> 1 eagle 197
> 2 camera 91
> 3 apple 89
> -------------------------
>
> Such a editing is easy in perl script but I cannot easily do that
> in command line.
>
> Is there any idea?

I'm not at all sure I understand what you are trying to do.
If you want to take the first set of data above, and end up with the 
second set, you can try a few different ways. Here is the input file:
$ cat test.txt
1 eagle 197
1 bird 387
2 camera 91
2 dog 62
3 apple 89

Using uniq:
If the numbers in the first field are small enough, tell uniq to only test 
the first (n) characters, like so (obviously, this will begin failing 
when we reach 100 in the first field):
$ uniq -w 2 test.txt
1 eagle 197
2 camera 91
3 apple 89

You could also use 'sort':
$ sort -nu test.txt
1 eagle 197
2 camera 91
3 apple 89

If the numbers in the first field are larger, sort should still work:
$ cat test.txt
1 eagle 197
1 bird 387
2 camera 91
2 dog 62
3 apple 89
10 cat 21
10 horse 22
99 orange 42
99 pear 44
100 grape 84
100 lime 88
101 lemon 23
102 fox 24
103 bear 25

$ sort -nu test.txt
1 eagle 197
2 camera 91
3 apple 89
10 cat 21
99 orange 42
100 grape 84
101 lemon 23
102 fox 24
103 bear 25

While uniq will fail:
$ uniq -w 2 test.txt
1 eagle 197
2 camera 91
3 apple 89
10 cat 21
99 orange 42
100 grape 84

Hope that helps and is what you were looking for,

- -- 
- -Michael

pgp key:  http://www.tuxfan.homeip.net:8080/gpgkey.txt
Red Hat Linux 7.{2,3}|8.0 in 8M of RAM: http://www.rule-project.org/
- --
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)

iD8DBQE+c+1Wn/07WoAb/SsRAjnZAJ9T2EZE0vqbnKAGxdLEubY/RrYwFACggsmu
CkjkCoJtZ8CA/leUlKDkcLs=
=F8Bn
-----END PGP SIGNATURE-----



-- 
redhat-list mailing list
unsubscribe mailto:[EMAIL PROTECTED]
https://listman.redhat.com/mailman/listinfo/redhat-list

Reply via email to