Giter VIP home page Giter VIP logo

selpg_go's Introduction

Selpg_GO

Selpg_GO is a Go version rewritten a Linux CLI named selpg and the original source code of selpg is written in c.

Introduction

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.

File Structure

  • 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

Code Analysis

  1. Import required packages in the project.
import (
	"bufio"
	"fmt"
	"io"
	"os"
	"os/exec"

	flag "pflag"
)
  1. 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
}
  1. 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()
  1. 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()

Test Case

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.

Case 1

input: $ selpg -s1 -e1 input_file

output:

// location: command line
1
2
...
72
E:\大三上各科\服务计算\selpg.exe: done

Case 2

input: $ selpg -s1 -e1 < input_file

output:

// location: command line
1
2
...
72
E:\大三上各科\服务计算\selpg.exe: done

Case 3

input: $ selpg -s1 -e1 input_file >output_file

output:

// location: output_file
1
2
...
72

// location: command line
E:\大三上各科\服务计算\selpg.exe: done

Case 4

input: $ selpg -s1 -e1 input_file 2>error_file

output:

// location: command line
1
2
...
72

// location: error_file
E:\大三上各科\服务计算\selpg.exe: done

Case 5

input: $ selpg -s1 -e10 -l1 input_file 2>error_file

output:

// location: command line
1
2
...
10

// location: error_file
E:\大三上各科\服务计算\selpg.exe: done

Reference

  1. 开发 Linux 命令行实用程序

  2. Golang reference

  3. 琦哥正义的帮♂助

selpg_go's People

Contributors

hongzicong avatar

Stargazers

Brave_Lion avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.