| 1 |
fragment |
| 2 |
|
| 3 |
This is a program to print a fragment of a file. It takes a filename, |
| 4 |
a starting line (lines are numbered starting at 1) and an optional |
| 5 |
end line or offset. It has one flag, `-nl`, which causes line numbers |
| 6 |
not to be printed. |
| 7 |
|
| 8 |
For example, compare the output to `nl -ba fragment.go`: |
| 9 |
|
| 10 |
$ fragment fragment.go 23 +6 |
| 11 |
23: func main() { |
| 12 |
24: flag.Parse() |
| 13 |
25: |
| 14 |
26: if flag.NArg() < 2 || flag.NArg() > 3 { |
| 15 |
27: usage() |
| 16 |
28: os.Exit(1) |
| 17 |
29: } |
| 18 |
|
| 19 |
$ fragment fragment.go 25 30 |
| 20 |
25: |
| 21 |
26: if flag.NArg() < 2 || flag.NArg() > 3 { |
| 22 |
27: usage() |
| 23 |
28: os.Exit(1) |
| 24 |
29: } |
| 25 |
30: |
| 26 |
|
| 27 |
$ fragment fragment.go 80 |
| 28 |
80 |
| 29 |
80: if n > end { |
| 30 |
81: return true |
| 31 |
82: } |
| 32 |
83: return false |
| 33 |
84: } |
| 34 |
85: |
| 35 |
86: fmt.Println(start) |
| 36 |
87: fmtStr += "\n" |
| 37 |
88: for i := start; !endFunc(i); i++ { |
| 38 |
89: fmt.Printf(fmtStr, i, lines[i]) |
| 39 |
90: } |
| 40 |
91: } |
| 41 |
|