Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I wrote a little program to parse hg log's command-line output, which happens to look like:

changeset:   90:abcdef012345
tag:         tip
user:        me
date:        Sat Apr 30 17:42:05 2011 -0700
summary:     Made another change

changeset:   89:def012345abc
user:        me
date:        Sat Apr 30 16:52:19 2011 -0700
summary:     Made a change

Actually, my program is generic enough to parse any "key: value" pairs, as long as each new record is separated by a blank line.

Now I want to go crazy and try running it against some other (real) data. Is there any other program that generates "key: value" data like this?

share|improve this question
    
An obscure one I use frequently is apcaccess to view the stats of my UPS. Won't produce good output unless you have one of those, though. –  ultrasawblade May 8 '11 at 0:19
add comment

1 Answer

With two commands, tr and sed, you can transform it to a more record-like format:

echo 'changeset:   90echo 'changeset:   90:abcdef012345
tag:         tip
user:        me
date:        Sat Apr 30 17:42:05 2011 -0700
summary:     Made another change

changeset:   89:def012345abc
user:        me
date:        Sat Apr 30 16:52:19 2011 -0700
summary:     Made a change
' | tr '\n' ';' | sed 's/;;/\n/' 
changeset:   90:abcdef012345;tag:         tip;user:        me;date:        Sat Apr 30 17:42:05 2011 -0700;summary:     Made another change
changeset:   89:def012345abc;user:        me;date:        Sat Apr 30 16:52:19 2011 -0700;summary:     Made a change;;

However, if it is your format, I would go to a more CSV-like format. You don't need to repeat the headline in every row, and with tabs instead of ';' or ',' (if you don't need tabs as content), you get a format which is very good to parse by hand, to compare rows, to grep rows with grep, and to produce graphs with LibreOffice or to put the data into a database.

If you have a more volatile format, xml might be better - not per se, but because there are so many tools out there.

In Chapter 5 of ESRs writing "The Art of Unix Programming, maybe you find some inspiration for your work.

share|improve this answer
    
Either I don't understand, or you don't understand. It's hg's format, not mine. I can already parse it just fine, and I wrote my program to run on systems that might not have tr and sed, anyway. I'm just looking for other programs which share this output format. I've read TAOUP but I'm following the tradition of non-Unix platforms this time: if text was sufficient for me I wouldn't have written a parser! :-) –  Ken May 8 '11 at 1:30
    
Which platform doesn't have tr and sed? You know the win32-ports for the gnu-tools? –  user unknown May 13 '11 at 1:12
    
The Windows servers I have to work on from time to time do not have that, but that's completely irrelevant because the question was about what other programs generate that format, not how to convert hg log output into CSV. –  Ken Jun 2 '11 at 14:03
    
Well - there a millions of programs to parse CSV-files, so it you transform the format to CSV, you can transform it from there to almonst anything else - put it into a SQL Database, open it with OpenOfficeCalc or any other spreadsheet program. –  user unknown Jun 2 '11 at 18:43
    
I'm not sure what you think I'm trying to do. I don't care about putting hg log output in a SQL database or opening it with a spreadsheet, and I apologize if I mistakenly gave that impression somehow. The use of hg log output in the question was merely as an example of what I am looking for, not what I need to process. –  Ken Jun 3 '11 at 5:51
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.