csv(3am)
π csv(3am) β the CSV glow-up for gawk π
okay so bestie, this is csv(3am), straight out of the GNU Awk Extension Modules. it's the page that teaches you how to make Comma-Separated-Values data with gawk, and honestly it's giving very much "small library, big slay" energy. let's get into it π
β¨ NAME β¨
csv β literally the facilities for creating Comma-Separated-Values (CSV) data with gawk. that's the whole vibe.
πΈ SYNOPSIS πΈ
@include "csv"
result = csvcompose(afield, option...)
result = csvformat(record, option...)
result = csvquote(field, option...)
three little functions, one @include, infinite lewks. π
π¦ DESCRIPTION π¦
The csv.awk library hands you control variables AND functions for composing CSV data records and fields. it's like a little makeup bag for your data β pick your delimiters, pick your quote char, go off. β¨
π the control variables (yes, they're literally just variables you set)
CSVFSβ the field separator you expect in the clean text record that's about to get formatted. defaults to the null character'\0'. lowkey an icon.CSVCOMMAβ the resulting CSV field delimiter. defaults to a comma','. shocking, i know.CSVQUOTEβ the resulting CSV quoting character. defaults to a double quote'"'. periodt.
π§ the functions
csvcompose(afield [, comma [, quote]])
returns a CSV formatted string by composing the values inside the afield array. the arguments, bestie:
afieldβ an array of field values, indexed from1toN. index 0 is not invited to the party, ok?commaβ optional. the resulting CSV field delimiter. defaults toCSVCOMMA.quoteβ optional. the resulting CSV quoting character. defaults toCSVQUOTE.
csvformat(record, [fs [, comma [, quote]]])
returns a CSV formatted string by composing the fields in the record string. arguments incoming:
recordβ a string record whose fields are delimited byfs.fsβ optional. the actual field separator inrecord. defaults toCSVFS.commaβ optional. the desired CSV field delimiter. defaults toCSVCOMMA.quoteβ optional. the desired CSV quoting character. defaults toCSVQUOTE.
csvquote(field [, comma [, quote]])
returns a CSV formatted string by escaping the required characters in the field string. so like, it handles the messy bits so you don't have to π«Ά. arguments:
fieldβ a single field clean text string.commaβ optional. the desired CSV field delimiter. defaults toCSVCOMMA.quoteβ optional. the desired CSV quoting character. defaults toCSVQUOTE.
π₯ EXAMPLES π₯
explicit CSV composition, and yes this example is literally James Bond, whoever wrote this ate:
f[1] = "007"
f[2] = "Bond, James"
f[3] = "United Kingdom"
result = csvcompose(f) # -> '007,"Bond, James",United Kingdom'
result = csvcompose(f, ";") # -> '007;Bond, James;United Kingdom'
record = "007/Bond, James/United Kingdom"
result = csvformat(record, "/") # -> '007,"Bond, James",United Kingdom'
result = csvformat(record, "/", ";") # -> '007;Bond, James;United Kingdom'
notice how "Bond, James" gets quoted because it's got a comma in it β that's the library doing the work so you don't have to. main character behavior tbh π
π NOTES π
the csv library automatically loads the CSV extension. no cap, you don't have to do it yourself. π¦
π BUGS π
literally nothing here. the section exists and it is empty. no bugs listed, it's feeling blessed. (don't come for me, that's genuinely all the page says π)
π AUTHOR π
Manuel Collado, m-collado@users.sourceforge.net. legend behavior, we stan. π«Ά
π SEE ALSO π
- CSV Processing With gawk
csvparse(3am)csvmode(3am)
go read them, they're the sibling icons of this lil family. β¨
πΈ COPYING PERMISSIONS πΈ
Copyright (C) 2018, Free Software Foundation, Inc.
Permission is granted to make and distribute verbatim copies of this manual page provided the copyright notice and this permission notice are preserved on all copies.
Permission is granted to copy and distribute modified versions of this manual page under the conditions for verbatim copying, provided that the entire resulting derived work is distributed under the terms of a permission notice identical to this one.
Permission is granted to copy and distribute translations of this manual page into another language, under the above conditions for modified versions, except that this permission notice may be stated in a translation approved by the Foundation.
π and that's the whole page bestie! brought to you by the GAWK Extension Library (gawkextlib), dated May 2016, filed under csv(3am). mwah πβ¨
π¦ where this page comes from
- nixos 26.05: gawkextlib-csv-unstable 2022-10-20
- nixpkgs unstable: gawkextlib-csv-unstable 2022-10-20
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms