Skip to content

Instantly share code, notes, and snippets.

@sthorne
Created February 20, 2015 16:56
Show Gist options
  • Save sthorne/122106bcdaec62c695cc to your computer and use it in GitHub Desktop.
Save sthorne/122106bcdaec62c695cc to your computer and use it in GitHub Desktop.
Read a file and Escape each line
package main
import (
"os"
"fmt"
"bufio"
"strconv"
)
func main() {
f, e := os.Open("file.txt")
if e != nil {
panic(e)
}
scanner := bufio.NewScanner(f)
for scanner.Scan() {
fmt.Println(strconv.Quote(scanner.Text()))
}
if e := scanner.Err(); e != nil {
panic(e)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment