or1ko's diary

日々を書きます

17

言語処理100本ノック 2015

17. 1列目の文字列の異なり
1列目の文字列の種類(異なる文字列の集合)を求めよ.確認にはsort, uniqコマンドを用いよ.

> Get-Content -Encoding utf8 .\hightemp.txt | ConvertFrom-Csv -Header a -Delimiter `t |
 % { $_.a } | Sort-Object -Unique
愛知県
愛媛県
岐阜県
群馬県
高知県
埼玉県
山形県
山梨県
静岡県
千葉県
大阪府
和歌山県

17.hs

import System.Environment
import System.IO.UTF8 as I8
import Data.List 

main = do
  filename <- getArgs >>= return . head
  body <- I8.readFile filename
  I8.writeFile "17.out.txt" $ unlines $ nub . sort . map (head . words) $ lines body

shのsortを動かくのが面倒だったため、PowerShellで実施することにした。