I have a few to questions pose in response first:-
What have you tried so far?
What output/errors do you get?
What are your preferred tools? (C, shell, perl, awk, etc.)
What logical process have you considered? (to help steer us to follow what you are trying to achieve)
Most importantly, What have you tried so far?
Whilst there is lots of useful information in your post, there are probably many ways to achieve most tasks, so giving us an idea of your style and thoughts will help us guide you to an answer most suitable to you so you can adjust it to suit your needs in future.
We're all here to learn and getting the relevant information will help us all.
Earlier we were getting this report in the Windows server and we had developed the VBS(VB Script) to perform the same.
Now it's coming to Linux System, so we have to start it from scratch.
I didn't started writing any code till now.
But as per my analysis "insert_job" is the 1st line for each attempt which is a catch here and if I can get the data from 1st "insert_job" to before the next insert_job then can grep each of them as per their 1st part of the line and get the 2nd part by using awk and then echo them to one single line.
Save as formatter.pl , run as perl formatter.pl [file1 file2 ...]
#!/usr/bin/perl
use strict;
use warnings;
#
# An ordered list of item labels.
my @ordered_labels = (
'insert_job',
'job_type',
'box_name',
'command',
'machine',
'owner',
'permission',
'date_conditions',
'std_out_file',
'std_err_file',
'alarm_if_fail',
'group',
'application',
'send_notification',
'notification_msg',
'notification_emailaddress',);
#
# Buffer db for all values on each group.
my %db;
display_header();
#
# Parse and collect values.
while(<>) {
#
# Inside a group
if(/^insert_job/../^\n/){
if(/^insert_job/) {
#
# First line has two pairs and value does not have
# spaces
while(/(\w+):\s(\w+)/g) {
$db{$1} = $2;
}
}
else {
#
# Parse only one pair that may contain all kind
# of characters as value, including spaces and quotes.
/(\w+):\s(.*$)/ and $db{$1} = $2;
}
#
# Display the data gathered and clear db for next time.
if(/^\n/) {
display_body();
%db = ();
}
}
}
# Display any data still in the db buffer.
display_body() if %db;
sub display_header {
print "JOB_NAME;JOB_TYPE;";
for(@ordered_labels[2..$#ordered_labels]) {
print "$_;";
}
print "\n";
}
sub display_body {
for my $i (@ordered_labels) {
if (defined $db{$i}){
$db{$i} =~ s/"//g;
print "$db{$i};";
}
else {
print " ;";
}
}
print "\n";
}