or1ko's diary

日々を書きます

12

言語処理100本ノック 2015

12. 1列目をcol1.txtに,2列目をcol2.txtに保存
各行の1列目だけを抜き出したものをcol1.txtに,2列目だけを抜き出したものをcol2.txtとしてファイルに保存せよ.確認にはcutコマンドを用いよ.

> cut -f 1 hightemp.txt > col1.txt
> cut -f 2 hightemp.txt > col2.txt

12.hs

import System.IO as I
import System.Environment
import System.IO.UTF8 as I8

main = do
  file <- getArgs >>= return . head
  body <- I8.readFile file
  let wss = map words $ lines body
  I.writeFile "col1.txt" $ unlines $ map head wss
  I.writeFile "col2.txt" $ unlines $ map (last . take 2) wss

実行結果は省略。