-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjoinCsv.hs
More file actions
32 lines (27 loc) · 829 Bytes
/
joinCsv.hs
File metadata and controls
32 lines (27 loc) · 829 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env stack
-- stack runghc
{-# LANGUAGE OverloadedStrings #-}
{-# OPTIONS_GHC -fno-warn-type-defaults #-}
import Control.Monad
import System.IO
import System.Environment
-- | 各行を連結
joinCsv :: [String] -> [String] -> [String]
joinCsv (x:xs) (y:ys) =
concat [x,",",y]:joinCsv xs ys
joinCsv (_:_) [] =
[""]
joinCsv [] (_:_) =
[""]
joinCsv [] [] =
[""]
-- | 文字コード指定読み込み
readFile' :: String -> String -> IO String
readFile' cp path = join $ hGetContents <$> openFile path ReadMode <* (flip hSetEncoding <$> mkTextEncoding cp)
-- | CSVファイルをJOINする
main :: IO ()
main = do
[left, right] <- getArgs
leftContent <- readFile' "UTF-8" left
rightContent <- readFile' "UTF-8" right
putStr $ unlines $ joinCsv (lines leftContent) (lines rightContent)