サーバーのよく使うコマンドメモ| sort

2015年2月20日

コマンド サーバー テクノロジー

Summery

表示行の並び替えを行う

Construction

$ sort [option] [file]

Option

-m : 複数のファイルに対応する -b : 先頭の空白を無視する(trimみたいな機能) -f : 大文字、小文字を区別せずに判断する -d : アルファベット、数字、スペースを対象にする -n : 先頭の記号と数値を数値として判断する -r : 逆ソートする -u : ユニーク表示(同一行がある場合は最初の1行のみ表示する) -o [file]:結果をfileに書き込む -k [pos1,pos2...] : keyを元にソートする

Sample

# file1とfile2を混ぜてソートする $ sort -m file1 file2 # 大文字とみなさないソート $ sort -t : -k 2,2 file1 # 大文字とみなすソート $ sort -f -t : -k 2,2 file1

Caution

メモリが16Mbを超えないように注意しよう。

Discription

Write sorted concatenation of all FILE(s) to standard output. Mandatory arguments to long options are mandatory for short options too. Ordering options: -b, --ignore-leading-blanks ignore leading blanks -d, --dictionary-order consider only blanks and alphanumeric characters -f, --ignore-case fold lower case to upper case characters -g, --general-numeric-sort compare according to general numerical value -i, --ignore-nonprinting consider only printable characters -M, --month-sort compare (unknown) < `JAN' < ... < `DEC' -n, --numeric-sort compare according to string numerical value -r, --reverse reverse the result of comparisons Other options: -c, --check check whether input is sorted; do not sort -k, --key=POS1[,POS2] start a key at POS1, end it at POS2 (origin 1) -m, --merge merge already sorted files; do not sort -o, --output=FILE write result to FILE instead of standard output -s, --stable stabilize sort by disabling last-resort comparison -S, --buffer-size=SIZE use SIZE for main memory buffer -t, --field-separator=SEP use SEP instead of non-blank to blank transition -T, --temporary-directory=DIR use DIR for temporaries, not $TMPDIR or /tmp; multiple options specify multiple directories -u, --unique with -c, check for strict ordering; without -c, output only the first of an equal run -z, --zero-terminated end lines with 0 byte, not newline --help display this help and exit --version output version information and exit POS is F[.C][OPTS], where F is the field number and C the character position in the field. OPTS is one or more single-letter ordering options, which override global ordering options for that key. If no key is given, use the entire line as the key. SIZE may be followed by the following multiplicative suffixes: % 1% of memory, b 1, K 1024 (default), and so on for M, G, T, P, E, Z, Y. With no FILE, or when FILE is -, read standard input. *** WARNING *** The locale specified by the environment affects sort order. Set LC_ALL=C to get the traditional sort order that uses native byte values.

人気の投稿

このブログを検索

ごあいさつ

このWebサイトは、独自思考で我が道を行くユゲタの少し尖った思考のTechブログです。 毎日興味がどんどん切り替わるので、テーマはマルチになっています。 もしかしたらアイデアに困っている人の助けになるかもしれません。

ブログ アーカイブ