~vcs-imports/gawk/master

« back to all changes in this revision

Viewing changes to awklib/eg/misc/quoted-csv.awk

  • Committer: Arnold D. Robbins
  • Date: 2024-10-15 02:57:20 UTC
  • mfrom: (2057.3.7)
  • Revision ID: git-v1:dca2fc9a1e801e5d01a019ba4a80b4fbc5961cfd
Merge branch 'gawk-5.3-stable'

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
BEGIN {
 
2
    FPAT = "([^,]*)|(\"([^\"]|\"\")+\")"
 
3
    OFS = "\t"    # Print tab-separated values
 
4
}
 
5
 
 
6
{
 
7
    for (i = 1; i <= NF; i++) {
 
8
        # Extract data from double-quoted fields
 
9
        if (substr($i, 1, 1) == "\"") {
 
10
            gsub(/^"|"$/, "", $i)    # Remove enclosing quotes
 
11
            gsub(/""/, "\"", $i)    # Convert "" to "
 
12
        }
 
13
    }
 
14
    $1 = $1     # force rebuild of the record
 
15
    print
 
16
}