Skip to content

Add helper functions for CSV processing #125

@benhoyt

Description

@benhoyt

It'd be good to add a library of various functions to help with processing CSV files (or other tabular data, it wouldn't be limited to CSV). For example:

  • The printrow() function mentioned in csv.md.
  • If we add the above, may also want a printheader() function that prints the names in OFIELDS (or just use print?).
  • A function to delete a field or fields, for example delfield(n) to delete a single field, or maybe delfield(n[, c]) to delete c fields starting at field n (c defaults to 1). For one implementation, see the rmcol definition in this StackOverflow answer.
    • Do we also need a delfieldbyname()? Though with a better name.
  • A function to insert a field or fields, eg insfield(n, val). With standard AWK you can kind of cheat with something like {$n=val FS $n;}, but that doesn't work for CSV escaping.

We could start by making this a simple AWK library that you include, eg goawk -f lib.awk -f prog.awk (prepend/append the library to the source when using the Go API).

When we want to add them as builtins to GoAWK, we should do it in a backwards-compatible way (i.e., not make them keywords like the other builtins, but if the user redefines a function or variable with that same name, that takes precedence).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions