Pages

lundi 14 octobre 2013

use Uniq command

I wanted to remove the lines which contains certain repeated characters. For example, my file is:

0  name0 2011 station
1  name1 2012 station
2  name2 2012 station
3  name3 2013 station

what I want to have is:
0  name0 2011 station

2  name2 2012 station
3  name3 2013 station

I used the command uniq:
cat file | uniq -f 2 
This command ignores the first 2 fields in the file and only evaluate the remaining fields.

There are also other interesting options of uniq:
-w: This option restricts comparison to first specified ‘N’ characters only. For this example, use the following test2 input file.

-s:  This option skips comparison of first specified ‘N’ characters. For this example, use the following test3 input file.



Aucun commentaire:

Enregistrer un commentaire