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
- Host: GitHub
- URL: https://github.com/hymkor/richcsv
- Owner: hymkor
- Created: 2022-02-18T15:44:45.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2022-02-18T16:30:30.000Z (about 3 years ago)
- Last Synced: 2025-02-10T15:50:56.651Z (3 months ago)
- Topics: awk, gawk
- Language: Awk
- Homepage:
- Size: 3.91 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
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>
```