csv(3am)

πŸ“¦ version 2022-10, in nixos 26.05, nixpkgs unstable

πŸ’– 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 from 1 to N. index 0 is not invited to the party, ok?
  • comma β€” optional. the resulting CSV field delimiter. defaults to CSVCOMMA.
  • quote β€” optional. the resulting CSV quoting character. defaults to CSVQUOTE.

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 by fs.
  • fs β€” optional. the actual field separator in record. defaults to CSVFS.
  • comma β€” optional. the desired CSV field delimiter. defaults to CSVCOMMA.
  • quote β€” optional. the desired CSV quoting character. defaults to CSVQUOTE.

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 to CSVCOMMA.
  • quote β€” optional. the desired CSV quoting character. defaults to CSVQUOTE.

πŸ”₯ 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 πŸ‘‘

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