1 Star 0 Fork 0

坐公交也用券/gcs

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
shellBase.go 1.28 KB
一键复制 编辑 原始数据 按行查看 历史
Nux 提交于 2023-03-16 22:57 . 升级gf
package gcs
import (
"fmt"
"gitee.com/liumou_site/gbm"
"gitee.com/liumou_site/gf"
"path"
"strings"
)
// Grep 通过关键词筛选所有匹配行
func (api *ApiShell) Grep(match string) *ApiShell {
api.gfs.Text = api.Strings
api.gfs.Grep(match)
api.Strings = api.gfs.Text
api.Err = api.gfs.Err
r := strings.Split(api.Strings, "\n")
api.Slice = gbm.SliceRemoveNull(r)
api.Err = api.gfs.Err
return api
}
// Echo 打印命令执行反馈信息
func (api *ApiShell) Echo() {
fmt.Println(api.Strings)
}
// AwkCol 打印命令执行反馈信息
func (api *ApiShell) AwkCol(col string) {
file := path.Join(api.home, "awk.tmp")
f := gf.NewFile(file)
f.Echo(api.Strings)
cmd := "awk '{print $" + col + "}' " + file
fmt.Println(cmd)
api.RunScript(cmd)
}
// Line 截取指定行
func (api *ApiShell) Line(n int) *ApiShell {
api.gfs.Text = api.Strings
api.gfs.Line(n)
api.Strings = api.gfs.Text
api.Err = api.gfs.Err
return api
}
// Column 截取指定列
func (api *ApiShell) Column(col int, sep string) *ApiShell {
if api.Debug {
logs.Debug(api.Strings)
}
sp := strings.Split(api.Strings, "\n")
sp = gbm.SliceRemoveNull(sp)
fmt.Println(sp)
fmt.Println(len(sp))
api.gfs.Text = api.Strings
api.gfs.Column(col, sep)
api.Strings = api.gfs.Text
api.Err = api.gfs.Err
return api
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/liumou_site/gcs.git
git@gitee.com:liumou_site/gcs.git
liumou_site
gcs
gcs
v1.8.1

搜索帮助