# Recutils as gophermap maker *Entered: in emacs on gemini pda* | *Date: 20220606* ## Recutils - text based database Gnu recutils has been discussed before by tomasino. I have had a TODO item for years at this point to check it out, and see if I had a use case for it. ## What to do with it? Fast forward to just now... I am on a plane to the Pacific Northwest reading the infotex on recutils and I am struck that you can trivially perform sed or awk like things with recutils. You can add fields on the fly, and assign values to those fields. So, you could do something like: ``` $ cd /var/gopher/Phlog $ ls *.post | \ sed 's/^.*$/printf "Date: &\\nTitle: \ $(head -1 & | sed "s@^# @@g;" | \ cut -c-50)\\n\\n"/g;' | \ sh | sed 's/\.post//g' > temp ``` Note: before someone rolls their eyes at piping to sh, as recently happened to me online -- this is my data. I do not have any phlog entries where the first line is ";rm -rf *", so settle down. Then you can query by year, for example and pipe your recordset into recfmt, which is a utility that is typically used for form letters, and have it spit out dynamic gophermap. ``` $ cat temp | recset -f Server -a "localhost" | \ recset -f Port -a 70 | recsel -e "Date ~ '2022'" | \ recfmt -f /var/gopher/tmplt | sort -r ``` The tmplt file looks like this: ``` 0{{Date}}: {{Title}}\t/Phlog/{{Date}}.post\t{{Server}}\t{{Port}} ``` Note: the actual file contains true tab characters where the \t appears above. This was the result of screwing around on the command line. I think if I use this to generate gophermaps for my phlog or other portions of this gopherhole, I would not ls the entire directory and dyanamically create the entire recordset each time. It makes more sense to have my publishing script append a new record for the new phlog entry after checking if it exists already to no create duplicates. I would want to pipe this to a plaintext gophermap file to avoid slowing down the server. ## Conclusion Gnu recutils can be used to store and format data in whatever manner you desire. If this had dawned upon me sooner I would be using it in many places.