Embed Notice
HTML Code
Corresponding Notice
- Embed this noticeI have a script I use to populate data into stansardized forms, like entire estate plans or corporate documents (.odt files), using data from a csv.
One of the most important processes in that script is being able to determine the name of a column based on row data, e.g. find a row that equals x and return the column name.
I looked at a few possible solutions. As far as I found, this was a pain using any standard database like postgres. It can be done, but it's far from elegant. I ended up using a combination of sed, awk, and a csv file to get the job done. The process is basically pull the row with sed (it relies on a counter to sequentially pull one row at a time - these tables aren't large, so it's easier this way), and then use awk count fields and return the field numbers for the matching data, and then again use sed to pull the first row odlf the csv, and awk to return the content of the field numbers returned from the previous process. It's simple and it works.