Sponsored Content
Full Discussion: Custom Report
Top Forums Shell Programming and Scripting Custom Report Post 303003334 by Aia on Tuesday 12th of September 2017 01:06:03 PM
Old 09-12-2017
A flexible Perl program.

Save as formatter.pl, run as perl formatter.pl [file1 file2 ...]
Code:
#!/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";
}

Output:
Code:
$ perl formatter.pl raw_file

JOB_NAME;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;
test_job_hu;CMD; ;sleep 600;localhost;account;gx,wx;0;/tmp/$AUTO_JOB_NAME.out;/tmp/$AUTO_JOB_NAME.err;1;P2;TBS_00_AXZCDE_Admin;1;test_job_hu job completed in HU NP;pradeep.agarwal@in.com;
test_machine;CMD;test_machine_box;echo $HOME;HULNXMACHINE;svc_account@hu.europe.com;gx,wx;0; ; ;1; ; ; ; ; ;

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to custom application name in `ps -ef`?

A program named /usr/bin/aa.sh, two parameters: 11, 22. after start it, the row in `ps -ef` is almost like the following: root 12198 10278 0.0 Nov 25 pts/3 0:00.23 /usr/bin/aa.sh 11 22 but I want to change "/usr/bin/aa.sh 11 22" to one rule string, such as: "AA_11_22", how to... (1 Reply)
Discussion started by: linkjack
1 Replies

2. Shell Programming and Scripting

Custom PS command

(0 Replies)
Discussion started by: goldfish
0 Replies

3. Shell Programming and Scripting

Custom auto-complete

Hello: I am using csh, and am a complete noob when it comes to shell scripting. I want the following: 1) Ignore case when doing auto-complete. 2) If there are multiple matches (example: I have files abc.txt abc.txt.1, abc.txt.2 and type abc<tab>), count the number of matches. If... (1 Reply)
Discussion started by: madiyaan
1 Replies

4. UNIX for Dummies Questions & Answers

Changing ip in a custom way

Hi. I hope someone can help me. I have e very special question. I have a Lunix server and I have installed Webmin on it. This way, I can create a login for an other user and give him restricted access to some custom commands I set up. One of the commands i would like to setup, is for him to... (9 Replies)
Discussion started by: Wonderke
9 Replies

5. AIX

Custom libraries possible on AIX 4.2 ?

I had started writting my own custom libraries on an AIX 4.2. Before finishing, I wanted to do a very simple test. So I wrote the followings: test.sh #!/bin/ksh . testlib.sh ZZ=testz "aa" "bb" echo "$ZZ" exit 0 testlib.sh testz () { return "$1$2" } When I ran my test.sh, I got an... (2 Replies)
Discussion started by: Browser_ice
2 Replies

6. Shell Programming and Scripting

doing own custom parameters

I have an rsync command that I want to create a variable where user can change to customize the parameters. complete rsync command to run: $RSYNC -e 'ssh -ax -o ClearAllForwardings=yes' --log-file=$LOG_FILE --delete -avzcr -u --update $SRC_DIR $USER@$TRG_SRV:$TRG_DIR >> $LOG_FILE What I... (4 Replies)
Discussion started by: abubin
4 Replies

7. Shell Programming and Scripting

custom command

hi I am trying to make my own commands in my linux.I thought a command for changing directories will be easy. I made a simple file amd made the entries #!/bin/bash cd /opt/mydir I then made the file executable and then moved it to /usr/bin. But when i type the script name nothing... (2 Replies)
Discussion started by: born
2 Replies

8. AIX

NPIV custom WWN

Hi All :) i would like to know if i can customize the WWN of the new VFC (NPIV). Or, if i must move the LPAR on another server with another FCS, i have to change the zoning?? Thanks in advance. Mario ---------- Post updated 09-21-12 at 02:51 AM ---------- Previous update was 09-20-12 at... (1 Reply)
Discussion started by: Zio Bill
1 Replies

9. Shell Programming and Scripting

Custom Shell

I have a jump off server, which grants SSH access to a few other servers. I would like to create a custom shell which can be assigned to specific user accounts which runs a menu script upon login, where they can select which server they want to jump too, however should they hit ctrl-c or any... (1 Reply)
Discussion started by: JayC89
1 Replies

10. Shell Programming and Scripting

Awking custom output

i have data that can look like this: echo "Master_Item_Service_is_down=0_njava_lang_NoClassDefFoundError=0_njava_lang_OutOfMemoryError=1_nemxCommonAppInitialization__Error_while_initializing=0_nINFO__Stopping_Coyote_HTTP_1_1_on_http_8080=7_nThe_file_or_directory_is_corrupted_and_unreadable=0_n" ... (7 Replies)
Discussion started by: SkySmart
7 Replies
Parse::MediaWikiDump::Links(3pm)			User Contributed Perl Documentation			  Parse::MediaWikiDump::Links(3pm)

NAME
Parse::MediaWikiDump::Links - Object capable of processing link dump files ABOUT
This object is used to access content of the SQL based category dump files by providing an iterative interface for extracting the indidivual article links to the same. Objects returned are an instance of Parse::MediaWikiDump::link. SYNOPSIS
$pmwd = Parse::MediaWikiDump->new; $links = $pmwd->links('pagelinks.sql'); $links = $pmwd->links(*FILEHANDLE); #print the links between articles while(defined($link = $links->next)) { print 'from ', $link->from, ' to ', $link->namespace, ':', $link->to, " "; } STATUS
This software is being RETIRED - MediaWiki::DumpFile is the official successor to Parse::MediaWikiDump and includes a compatibility library called MediaWiki::DumpFile::Compat that is 100% API compatible and is a near perfect standin for this module. It is faster in all instances where it counts and is actively maintained. Any undocumented deviation of MediaWiki::DumpFile::Compat from Parse::MediaWikiDump is considered a bug and will be fixed. METHODS
Parse::MediaWikiDump::Links->new Create a new instance of a page links dump file parser $links->next Return the next available Parse::MediaWikiDump::link object or undef if there is no more data left EXAMPLE
List all links between articles in a friendly way #!/usr/bin/perl use strict; use warnings; use Parse::MediaWikiDump; my $pmwd = Parse::MediaWikiDump->new; my $links = $pmwd->links(shift) or die "must specify a pagelinks dump file"; my $dump = $pmwd->pages(shift) or die "must specify an article dump file"; my %id_to_namespace; my %id_to_pagename; binmode(STDOUT, ':utf8'); #build a map between namespace ids to namespace names foreach (@{$dump->namespaces}) { my $id = $_->[0]; my $name = $_->[1]; $id_to_namespace{$id} = $name; } #build a map between article ids and article titles while(my $page = $dump->next) { my $id = $page->id; my $title = $page->title; $id_to_pagename{$id} = $title; } $dump = undef; #cleanup since we don't need it anymore while(my $link = $links->next) { my $namespace = $link->namespace; my $from = $link->from; my $to = $link->to; my $namespace_name = $id_to_namespace{$namespace}; my $fully_qualified; my $from_name = $id_to_pagename{$from}; if ($namespace_name eq '') { #default namespace $fully_qualified = $to; } else { $fully_qualified = "$namespace_name:$to"; } print "Article "$from_name" links to "$fully_qualified" "; } perl v5.10.1 2010-12-05 Parse::MediaWikiDump::Links(3pm)
All times are GMT -4. The time now is 11:00 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy