首页 > 科技 > sort

sort

2006年2月11日 10点22分 发表评论 阅读评论

Sort, sort lines of text files.
syntax:
sort -c -m -u -o output-file [other options] +pos1.+pos2 input_files
-c : to check the text has been sorted
-m : combine two sorted files
-u : delete all duplicate characters to keep contents unique.
-o : write result to a file instead of standard output
-t : the default seperator is space, but we can also identify other characters by using “-t”.
-r : revers the sort sequence.
+pos1 : indicate the fields which will be sorted
+pos2 : indicate the character position which will be sorted
Note, the fieid and characters’ sequence are not as same as they are described in RE.These sequence account from 0 not 1.for example:
My name is Phillip Huang
Fields 0 1 2 3 4

P h i l l i p
Character 0 1 2 3 4 5 6

pos usage:
# sort +field_number.characters_number
Then ,the command line “# sort +4.6 input-file” means sort operation will be start from 5th fields, 7th character.

If we only execute the following command “# sort filename” without any options and specified fields or characters, sort will make the field 0 as default automatically.

sort by numeric field:
# sort -t: +3n video.txt
if “n” character is not used here, the result would be like following:
1789
2562
400
In fact, the output is not what we want because it is sorted by the first number of the numberic string.What will be if the “n”
character added?
# sort -t +3n video.txt
400
1789
2562
This operation sorted with the whole numeric string gives the right answer.

By using “-k” option, it is impossible for us to identify the first partition as field 1 just as RE. This way is more easily used which should not confuse us.for example:
# sort -t: -k4 video.txt

分类: 科技 标签:
  1. 本文目前尚无任何评论.
  1. 本文目前尚无任何 trackbacks 和 pingbacks.
您必须在 登录 后才能发布评论.