How can I turn this ugly output into pretty, useful data?The output:/* ---------- TA#box#AbC_p ---------- */insert_job: TA#box#AbC_p    job_type: a#owner: bobpermission: gxdate_conditions: 1days_of_week: sustart_times: 16:15run_window: 16:15-17:30description: Job AbC that runs at 4:15PM on Sundays, and should end before 5:30PM    /* ---------- TA#cmd#EfGJob_p ---------- */    insert_job: TA#cmd#EfGJob_p    job_type: b    box_name: TA#box#AbC_p    command: /path/to/shell/script.sh    machine: vm_machine1    #owner: alex    permission: gx    date_conditions: 2    run_window: 16:20-16:30    description: job EfG that runs within box AbC    term_run_time: 60    std_out: /path/to/log.log    std_err: /path/to/err.log    alarm_if_fail: 1    profile: /path/to/profileand so on, for a long time. #cmd# jobs are sometimes under a #box#. If they are under a #box#, the #cmd# section is indented.My ideal output would be something like:Job Name, Time, Schedule, Machine, Description, CommandTA#box#AbC_p, 16:15, su, , Job AbC that runs at 4:15PM on Sundays, and should end before 5:30PM, TA#cmd#EfGJob_p, 16:15, su, vm_machine1, job EfG that runs within box AbC, /path/to/shell/script.shI'm trying awk, perl and grep, but I'm having trouble keeping all the info for one section together before I print the CSV line.
How can I turn ugly output into pretty, useful information?
bash;awk;perl;csv;text
I'd use Perl for that, or at least awk.perl -ne '    BEGIN {        print \Job Name\, \Time\, \Schedule\, \Machine\, \Description\, \Command\, \\n;    }    chomp; s/^\s+//; s/\s+$//;    if (($_ eq  || eof) && exists $fields{insert_job}) {        print \, join(\, \, @fields{qw(insert_job start_times days_of_week machine description command)}), \\n;        delete @fields{qw(insert_job)};    }    if (/^([^ :]+): *(.*)/) {$fields{$1} = $2}'Explanations:The BEGIN block is run once at the beginning of the script, the rest runs for every input line.The line that begins with chomp strips off leading and trailing whitespace.The first if line triggers on empty lines (paragraph separators), if the field insert_job is present.The delete line removes the insert_job field. Add other field names that you don't want to spill over from one paragraph to the next.The last if line stores fields.