sortは引数でファイルパスを受け取れる
タイトルですべてなのですが。
この二つは同じ結果になります。
sort sample.txt
cat sample.txt | sort
感覚的には↓と同じになってしまいそうなんですが。
[webmaster@localhost sh]$ echo sample.txt | sort sample.txt [webmaster@localhost sh]$
引数で受け取ればファイルの中身を読み取れるようです。
実行例は以下の通り。
[webmaster@localhost sh]$ cat sample.txt hoge foo hoge var あああ [webmaster@localhost sh]$ [webmaster@localhost sh]$ cat sample.txt | sort あああ foo hoge hoge var [webmaster@localhost sh]$ sort sample.txt あああ foo hoge hoge var [webmaster@localhost sh]$
ちなみにuniqもファイル名を引数で受け取れますが、基本はsortと組み合わせなので、sortをかませないと意図する結果とはなりません。
[webmaster@localhost sh]$ uniq sample.txt hoge foo hoge var あああ [webmaster@localhost sh]$ sort sample.txt | uniq あああ foo hoge var [webmaster@localhost sh]$