An open API service indexing awesome lists of open source software.

https://github.com/hymkor/richcsv

Pure gawk template for reading CSV files containing line breaks in elements
https://github.com/hymkor/richcsv

awk gawk

Last synced: 24 days ago
JSON representation

Pure gawk template for reading CSV files containing line breaks in elements

Awesome Lists containing this project

README

        

richcsv.awk
===========

Pure gawk Template for reading CSV files containing line breaks in elements.
(Test on gawk 5.1.1)

```awk
BEGIN{
FPAT="([^,]+)|(\"[^\"]+\")"
}

{
last = last $0
if ( last != "" && split(last,trash,"\"") % 2 == 0 ){
last = last RS
next
}
$0 = last ; last = ""
}

# test
{
for(i = 1 ; i <= NF ; i++ ){
printf "<%s>",gensub("\"","","g",$i)
}
print ""
}
```

```
$ type sample.csv
0001,=1+1,03,-4,5/2
"hogeohg 2",5555,3,"1st TEXT
2nd
3rd
4th"
$ gawk -f richcsv.awk sample.csv
<0001><=1+1><03><-4><5/2>
<5555><3><1st TEXT
2nd
3rd
4th>
```