I have a file with tab-delimited values in this format:
your-email your-order-id PayPal-transaction-id your-first-name your-second-name [email protected] 12345 54321 sooky spooky [email protected] 23456 23456 kiki dee [email protected] 34567 76543 cheeky chappy and I'd like to use awk to convert this to YAML:
--- your-email: [email protected] your-order-id: 12345 PayPal-transaction-id: 54321 your-first-name: sooky your-second-name: spooky your-email: [email protected] your-order-id: 23456 PayPal-transaction-id: 23456 your-first-name: kiki your-second-name: dee your-email: [email protected] your-order-id: 34567 PayPal-transaction-id: 76543 your-first-name: cheeky your-second-name: chappy So far, my awk script looks like this:
#!/usr/bin/awk FS=="\t" BEGIN {print "---"} NR==1 {for (i=1;i<=NF;i++) print $i ": "} But I can't figure out how to get each field from line 1 onwards to print after its header and recreate the YAML key values from the first line of the input file. In the real file, there are 38 fields and 34 records (so not huge).
----- or you want a list of dictionaries (that would be my preferred choice.), in which case you should prefix theyour-emaillines with-and indent the other non-blank ones two spaces. See the YAML reference-card.