Selpg_GO
is a Go
version rewritten a Linux
CLI named selpg
and the original source code of selpg
is written in c
.
Selgo_GO
can be used to extract only a specified range of pages from an input text file and then print the output file in the command line, a file or anywhere you like.
-
selpg.go: the Go version of selpg
-
input_file: the file used to input
-
output_file: the file used to output result
-
error_file: the file used to output error record
- Import required packages in the project.
import (
"bufio"
"fmt"
"io"
"os"
"os/exec"
flag "pflag"
)
- A struct which is the core of selpg.
type sp_args struct {
start_page int
end_page int
in_filename string
page_len int
page_type bool
print_dest string
}
- Input the arguments of command line, check them for validity and then construct a
sp_args
struct based on the user's input arguments.
func (sa *sp_args) process_args()
- Process the input and output the result and error record into the specified locations accroding to the
sp_args
.
func (sa sp_args) process_input()
Typng an instruction $ sh ./test.sh
in command line.
// test.sh
for i in {1..7200}
do
echo $i >> input_file
done
Then we can get a text file consisting of 7200 numbers from 1 to 7200 and each number occupies one line.
input: $ selpg -s1 -e1 input_file
output:
// location: command line
1
2
...
72
E:\大三上各科\服务计算\selpg.exe: done
input: $ selpg -s1 -e1 < input_file
output:
// location: command line
1
2
...
72
E:\大三上各科\服务计算\selpg.exe: done
input: $ selpg -s1 -e1 input_file >output_file
output:
// location: output_file
1
2
...
72
// location: command line
E:\大三上各科\服务计算\selpg.exe: done
input: $ selpg -s1 -e1 input_file 2>error_file
output:
// location: command line
1
2
...
72
// location: error_file
E:\大三上各科\服务计算\selpg.exe: done
input: $ selpg -s1 -e10 -l1 input_file 2>error_file
output:
// location: command line
1
2
...
10
// location: error_file
E:\大三上各科\服务计算\selpg.exe: done