quired output in form of


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting quired output in form of
# 1  
Old 11-25-2011
Question quired output in form of

hi frnds,

i have a file:

where 1st field is:
eventType,eventTime,loggingTime, probableCause,lsname,slCode

and is 2nd field hav its values and everytime its starting with communicationsAlarm
on the behalf of communicationsAlarm

eventType communicationsAlarm,
eventTime "20111103164448",
loggingTime "20111103164549",
probableCause slFailure,
lsname "VP2HPSGM01L3"
slCode = 5
eventType communicationsAlarm,
eventTime "20111103164448",
loggingTime "20111103164549",
probableCause slFailure,
lsname "VP2HPSHL01L3"
slCode = 6
eventType communicationsAlarm,
eventTime "20111103141027",
loggingTime "20111103141128",
probableCause slFailure,
lsname "VP2HPSGM01L3"
slCode = 6
eventType communicationsAlarm,
eventTime "20111103141027",
loggingTime "20111103141128",
probableCause slFailure,
lsname "VP2HPSHL01L3"
slCode = 5
eventType communicationsAlarm,
eventTime "20111103141027",
loggingTime "20111103141128",
probableCause slFailure,
lsname "VP2HPSHL01L3"
slCode = 14


a
on the behalf of communicationsAlarm i want output as :
if any filed does not hav any value i want print null

eventType,eventTime,loggingTime, probableCause,lsname,slCode
communicationsAlarm,20111103164448,20111103164549,slFailure,VP2HPSGM01L3,5 communicationsAlarm,20111103164448,20111103164549,NULL,VP2HPSGM01L3,5
communicationsAlarm,20111103131313,20111103164549,slFailure,VP2HPSGM01L3,5
# 2  
Old 11-25-2011
Why can't you use code tags?

What does "quired" mean? In fact, what is "quired output in form of" supposed to convey as a meaning?
# 3  
Old 12-02-2011
input.txt:
Code:
eventType communicationsAlarm,
eventTime "20111103164448",
loggingTime "20111103164549",
probableCause
lsname "VP2HPSGM01L3"
slCode = 5
eventType communicationsAlarm,
eventTime "20111103164448",
loggingTime "20111103164549",
probableCause slFailure,
lsname "VP2HPSHL01L3"
slCode = 6
eventType communicationsAlarm,
eventTime "20111103141027",
loggingTime "20111103141128",
probableCause
lsname "VP2HPSGM01L3"
slCode = 6
eventType communicationsAlarm,
eventTime "20111103141027",
loggingTime "20111103141128",
probableCause slFailure,
lsname "VP2HPSHL01L3"
slCode = 5
eventType communicationsAlarm,
eventTime
loggingTime "20111103141128",
probableCause slFailure,
lsname "VP2HPSHL01L3"
slCode = 14

Code:
#! /usr/bin/perl -w
use strict;

my (%x, @y);
my ($ln, $i) = (0, 1);

open INPUT, "< input.txt";
open OUTPUT, ">> output.txt";
print OUTPUT "eventType,eventTime,loggingTime, probableCause,lsname,slCode\n";
for $ln ( <INPUT> ) {
    if ($ln =~ /=/) {
        $ln =~ s/ = / /;
    }
    @y = split /\s+/, $ln;
    if ($#y == 0) {
        $y[1] = "NULL";
    }
    $y[1] =~ s/"//g;
    if ($y[1] !~ /,$/) {
        $y[1] =~ s/(\w+)/$1,/ unless ($y[1] =~ /^\d+$/);
    }
    print OUTPUT "$y[1]";
    if ($i == 6) {
        print OUTPUT "\n";
        $i = 0;
    }
    $i++;
}
close OUTPUT;
close INPUT;

output.txt:
Code:
eventType,eventTime,loggingTime, probableCause,lsname,slCode
communicationsAlarm,20111103164448,20111103164549,NULL,VP2HPSGM01L3,5
communicationsAlarm,20111103164448,20111103164549,slFailure,VP2HPSHL01L3,6
communicationsAlarm,20111103141027,20111103141128,NULL,VP2HPSGM01L3,6
communicationsAlarm,20111103141027,20111103141128,slFailure,VP2HPSHL01L3,5
communicationsAlarm,NULL,20111103141128,slFailure,VP2HPSHL01L3,14

# 4  
Old 12-02-2011
below perl may give you some clue

while(<DATA>){
my $str = "eventType".$_;
if($str=~/^(?:eventType)+\s+([^,]+).*eventTime[^\d]+(\d+)/s){
print $1," ",$2,"\n";
}
}
__DATA__
your data here
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Dispaying output in tabular form

hi, I have a script which is dispaying the output as below: Column 3:value1 Column 4:value 4 column 8:value 8 column 9:value 9 column 13:value 13 Column 3:value10 Column 4:value 40 column 8:value 80 column 9:value 90 column 13:value 103 However,I need the output in tabular... (5 Replies)
Discussion started by: Vivekit82
5 Replies

2. Shell Programming and Scripting

Displaying log file pattern output in tabular form output

Hi All, I have result log file which looks like this (below): from the content need to consolidate the result and put it in tabular form 1). Intercomponents Checking Passed: All Server are passed. ====================================================================== 2). OS version Checking... (9 Replies)
Discussion started by: Optimus81
9 Replies

3. Shell Programming and Scripting

Remove x lines form top and y lines form bottom using AWK?

How to remove x lines form top and y lines form bottom. This works, but like awk only cat file | head -n-y | awk 'NR>(x-1)' so remove last 3 lines and 5 firstcat file | head -n-3 | awk 'NR>4' (5 Replies)
Discussion started by: Jotne
5 Replies

4. Shell Programming and Scripting

Transpose Data form Different form

HI Guys, I have data in File A.txt RL03 RL03_A_1 RL03_B_1 RL03_C_1 RL03 -119.8 -119.5 -119.5 RL07 RL07_A_1 RL07_B_1 RL07_C_1 RL07 -119.3 -119.5 -119.5 RL15 RL15_A_1 RL15_C_1 RL15 -120.5 -119.4 RL16... (2 Replies)
Discussion started by: asavaliya
2 Replies

5. Shell Programming and Scripting

Net::SSH::Perl->Execute any unix command & display the output in a proper form

Net::SSH::Perl ...... how to print the output in a proper format my $cmd = "ls -l"; my $ssh = Net::SSH::Perl->new($host); $ssh->login($user, $pass); my($stdout, $stderr, $exit) = $ssh->cmd("$cmd"); print $stdout; the script works fine, but i am unable to see the output... (2 Replies)
Discussion started by: gsprasanna
2 Replies

6. Shell Programming and Scripting

need encrypt form

Hi, i need to encrypt and decrypt of a string. pls provide me some syntax or any method available using shell script. i know one method i.e., perl -e 'print pack "H*","message"' so if perl command doesnt work then what is the other method to encrypt and decrypt. Thanks in advance. (0 Replies)
Discussion started by: syamkp
0 Replies

7. UNIX for Advanced & Expert Users

How to parse through a file and based on condition form another output file

I have one file say CM.txt which contains values like below.Its just a flat file 1000,A,X 1001,B,Y 1002,B,Z ... .. total around 4 million lines of entries will be in that file. Now i need to write another file CM1.txt which should have 1000,1 1001,2 1002,3 .... ... .. Here i... (6 Replies)
Discussion started by: sivasu.india
6 Replies

8. Shell Programming and Scripting

help on formatting output (Table Form)

Data in File ABC:DEFGHI:123 ABCZYE:DEFI:123 ABCFGD:DEF:123 ABCEERRRRR:DEFGHI:123 Expected Format 1 ABC DEFGHIFE 123 2 ABCZYE DEFI 123 3 ABCFGD DEF 123 4 ABCEERRRRR DEFGHI 123 However when i enter the following... (2 Replies)
Discussion started by: blurboy
2 Replies

9. UNIX for Advanced & Expert Users

Changing Unix form to Microsoft Word form to be able to email it to someone.

Please someone I need information on how to change a Unix form/document into a microsoft word document in order to be emailed to another company. Please help ASAP. Thankyou :confused: (8 Replies)
Discussion started by: Cheraunm
8 Replies
Login or Register to Ask a Question