2015-09-22 08:46:54 +00:00
|
|
|
fragment
|
|
|
|
|
|
|
|
This is a program to print a fragment of a file. It takes a filename,
|
|
|
|
a starting line (lines are numbered starting at 1) and an optional
|
2015-12-23 04:54:59 +00:00
|
|
|
end line or offset. It has one flag, `-nl`, which causes line numbers
|
|
|
|
not to be printed.
|
2015-09-22 08:46:54 +00:00
|
|
|
|
|
|
|
For example, compare the output to `nl -ba fragment.go`:
|
|
|
|
|
|
|
|
$ fragment fragment.go 23 +6
|
|
|
|
23: func main() {
|
|
|
|
24: flag.Parse()
|
|
|
|
25:
|
|
|
|
26: if flag.NArg() < 2 || flag.NArg() > 3 {
|
|
|
|
27: usage()
|
|
|
|
28: os.Exit(1)
|
|
|
|
29: }
|
|
|
|
|
|
|
|
$ fragment fragment.go 25 30
|
|
|
|
25:
|
|
|
|
26: if flag.NArg() < 2 || flag.NArg() > 3 {
|
|
|
|
27: usage()
|
|
|
|
28: os.Exit(1)
|
|
|
|
29: }
|
|
|
|
30:
|
|
|
|
|
|
|
|
$ fragment fragment.go 80
|
|
|
|
80
|
|
|
|
80: if n > end {
|
|
|
|
81: return true
|
|
|
|
82: }
|
|
|
|
83: return false
|
|
|
|
84: }
|
|
|
|
85:
|
|
|
|
86: fmt.Println(start)
|
|
|
|
87: fmtStr += "\n"
|
|
|
|
88: for i := start; !endFunc(i); i++ {
|
|
|
|
89: fmt.Printf(fmtStr, i, lines[i])
|
|
|
|
90: }
|
|
|
|
91: }
|
|
|
|
|