GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - spakin/awk: Easy AWK-style text processing in Go

BranchesTags
Open more actions menu

Latest commit

 

History

84 Commits
84 Commits

Folders and files

NameName
Last commit message
Last commit date
.travis.yml
.travis.yml
 
 
LICENSE.md
LICENSE.md
 
 
README.md
README.md
 
 
assoc.go
assoc.go
 
 
assoc_test.go
assoc_test.go
 
 
doc.go
doc.go
 
 
example_test.go
example_test.go
 
 
go.mod
go.mod
 
 
script.go
script.go
 
 
script_test.go
script_test.go
 
 
value.go
value.go
 
 
value_test.go
value_test.go
 
 

Repository files navigation

awk

Go Report Card Build Status Go project version GoDoc

Description

awk is a package for the Go programming language that provides an AWK-style text processing capability. The package facilitates splitting an input stream into records (default: newline-separated lines) and fields (default: whitespace-separated columns) then applying a sequence of statements of the form "if 〈pattern〉 then 〈action〉" to each record in turn. For example, the following is a complete Go program that adds up the first two columns of a CSV file to produce a third column:

package main

import (
    "github.com/spakin/awk"
    "os"
)

func main() {
    s := awk.NewScript()
    s.Begin = func(s *awk.Script) {
        s.SetFS(",")
        s.SetOFS(",")
    }
    s.AppendStmt(nil, func(s *awk.Script) {
        s.SetF(3, s.NewValue(s.F(1).Int()+s.F(2).Int()))
        s.Println()
    })
    s.Run(os.Stdin)
}

In the above, the awk package handles all the mundane details such as reading lines from the file, checking for EOF, splitting lines into columns, handling errors, and other such things. With the help of awk, Go easily can be applied to the sorts of text-processing tasks that one would normally implement in a scripting language but without sacrificing Go's speed, safety, or flexibility.

Installation

The awk package has opted into the Go module system so installation is in fact unnecessary if your program or package has done likewise. Otherwise, a traditional

go get github.com/spakin/awk

will install the package.

Documentation

Descriptions and examples of the awk API can be found online in the GoDoc documentation of package awk.

Author

Scott Pakin, [email protected]

About

Easy AWK-style text processing in Go

Resources

Readme
BSD-3-Clause license
Activity

Stars

97 stars

Watchers

7 watching

Forks

6 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.