Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

github.com/spakin/awk

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/spakin/awk

  • v1.0.0
  • Source
  • Go
  • Socket score

Version published
Created
Source

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, scott+awk@pakin.org

FAQs

Package last updated on 17 Jul 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc