Today's challenge: your editors just handed you almost 200 taxonomy terms to add to the site, and you don't have the time or inclination to hit the taxonomy/n/add/term page for the next 2 hours or so... AWK to the rescue!
Doing a simple CSV export of the term_data and term_hierarchy tables, you've got a pretty simple structure:
What you'll ultimately generate here is a file that stores everything you need to know about importing these terms via a CSV - the term names, the weights, good IDs, and the TID of the parents.
2048,#the current value of the sequences for term_data
term,34,Blogs,#a helper line
x,1,Drupal,All about Drupal,-5
x,1,Modules,Ways to extend Drupal,-4
x,1,Themes,Making your install pretty,-3
term,35,News,#a second helper line
In this file, we've got 3 types of data:
- The starting value for sequences
- The id of the parent term for the next several rows, starting with the word "term" followed by the TID and the plain English name just to help us get organized
- The new terms, with an "x" where the new TIDs will be placed, and the VID, Description and Weight all filled out.