Last active
December 15, 2024 23:00
-
-
Save rowinf/87cc1b11bf6cfc0bc55e2cdb740ac03f to your computer and use it in GitHub Desktop.
concatenate text that was stripped from html table and format it as a csv
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### | |
# this text was processed from a curl + pup command | |
# surrounding html tags were stripped from the text | |
# each line of text was from a table cell | |
# recombine table cells into a csv | |
### | |
NR < 16 { | |
headers = (headers == "" ? $0 : headers ", " $0) | |
next | |
} | |
NR == 16 { | |
sub(",", "", headers) # commas are removed from locations | |
print headers | |
} | |
/[a-zA-Z]/ { | |
if (numbers != "") { | |
print names ", " numbers | |
names = "" | |
numbers = "" | |
} | |
gsub(",", "", $0) | |
names = (names == "" ? $0 : names " " $0) | |
next | |
} | |
/[0-9]/ { | |
gsub(",", "", $0) | |
numbers = (numbers == "" ? $0 : numbers ", " $0) | |
} | |
END { | |
if (names != "" || numbers != "") { | |
print names ", " numbers | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment