Haskell file reading

Not a bad start! The only thing to remember is that pure function application should use let instead of the binding <-. import System.IO import Control.Monad main = do let list = [] handle <- openFile “test.txt” ReadMode contents <- hGetContents handle let singlewords = words contents list = f singlewords print list hClose handle … Read more

Golang Determining whether *File points to file or directory

For example, package main import ( “fmt” “os” ) func main() { name := “FileOrDir” fi, err := os.Stat(name) if err != nil { fmt.Println(err) return } switch mode := fi.Mode(); { case mode.IsDir(): // do directory stuff fmt.Println(“directory”) case mode.IsRegular(): // do file stuff fmt.Println(“file”) } } Note: The example is for Go 1.1. … Read more

How do I split a file into n no of parts

In bash, you can use the split command to split it based on number of lines desired. You can use wc command to figure out how many lines are desired. Here’s wc combined with with split into one line. For example, to split onepiece.log into 5 parts split -l$((`wc -l < onepiece.log`/5)) onepiece.log onepiece.split.log -da … Read more