-4

We are trying to convert the output received from the below code

The current output is in this form

testingwindows,1446727960,1446728560,kkulka11,testingwin
testingwindows1,1446727160,141228560,kkulka11,testingwin
testingwindows2,1446727120,1446728560,kkulka11,testingwin
testingwindows3,1446727960,1446728560,kkulka11,testingwin

The output required is something like

testingwindows from Fri Oct  3 13:51:05 2015 GMT to Mon Nov  9 13:51:05 2015 GMT by kkulka11 for testingwin.
testingwindows1 from Fri Oct 2 13:51:05 2015 GMT to Mon Nov  9 13:51:05 2015 GMT by kkulka11 for testingwin.
testingwindows2 from Fri Oct 2 13:51:05 2015 GMT to Mon Nov  9 13:51:05 2015 GMT by kkulka11 for testingwin.
testingwindows3 from Fri Oct 12 13:51:05 2015 GMT to Mon Nov  9 13:51:05 2015 GMT by kkulka11 for testingwin.

This is my current code

if ( $COMMAND eq 'queryone' ) {
    my $msend_query = "$MCELL_HOME\\bin\\mquery";
    my @args_query = (
        $msend_query,
        "-q",
        "-c", "$MCELL_HOME\\etc\\mclient.conf",
        "-n", "$CS_BLACKOUT_CELL",
        "-d",
        "-f", "csv",
        "-a", "CS_EMB_GBF_BLACKOUTS" ,
        "-s", "blackout_host,start_timestamp,stop_timestamp,userid,reason",
        "-w", "blackout_host: == '${BLACKOUTHOST}'"
    );
    system(@args_query);

We tried using perl -pe 's/(\d{10})/gmtime($1)/e'; but not able to convert and it gives this error

'o~}go⌂⌂t⌂x⌂w' is not recognized as an internal or external command, operable program or batch file.

when we used the code as

if ( $COMMAND eq 'queryone' ) {
    my $msend_query = "$MCELL_HOME\\bin\\mquery";
    my $mqt = "$MCELL_HOME\\mqt.pl";
    my @args_query = (
        $msend_query,
        "-q",
        "-c", "$MCELL_HOME\\etc\\mclient.conf",
        "-n", "$CS_BLACKOUT_CELL",
        "-d",
        "-f", "csv",
        "-a", "CS_EMB_GBF_BLACKOUTS",
        "-s", "blackout_host,start_timestamp,stop_timestamp,userid,reason",
        "-w", "blackout_host: == '${BLACKOUTHOST}'"
    ) | $mqt;
    system(@args_query);

Needed experts quick help and guidance to achieve the output in human-readable format.

Edit:

Updated the code as per Jacob comments but still not received the output as desired. Please suggest

if ( $COMMAND eq 'queryone' ) {
    my $msend_query = "$MCELL_HOME\\bin\\mquery";
    my @args_query = (
        $msend_query,
        "-q",
        "-c", "$MCELL_HOME\\etc\\mclient.conf",
        "-n", "$CS_BLACKOUT_CELL",
        "-d",
        "-f", "csv",
        "-a", "CS_EMB_GBF_BLACKOUTS" ,
        "-s", "blackout_host,start_timestamp,stop_timestamp,userid,reason",
        "-w", "blackout_host: == '${BLACKOUTHOST}'"
    );
    chomp;
    my @parts = split(/,/, system(@args_query));
    $parts[1] = localtime($parts[1]);
    $parts[2] = localtime($parts[2]);
    printf("%s from %s to %s by %s for %s\n", @parts);
}

Output:

M:\AbhayBackup\PerlKK>test.pl -q -h testingwin
testingwin
sub: testingwin
testingwin,1446727960,1446728560,kkulka11,testingwin
0 from Thu Jan  1 05:30:00 1970 to Thu Jan  1 05:30:00 1970 by  for
Borodin
  • 126,100
  • 9
  • 70
  • 144
Newbie
  • 1
  • 1
  • `... ) | $mqt;` - you're doing a bitwise OR of your command string. This makes no sense. – melpomene Nov 08 '15 at 14:51
  • @melpomene .. suggest what we may do to correct the same . In Unix script we did using perl -pe in the mqt.pl and prnted the output using awk -F but in windows same does not work ..hence needed your suggestions – Newbie Nov 08 '15 at 15:34
  • 1
    "Correct" how? I have no idea what your code is trying to do there. Why did you put bitwise operations in there in the first place? – melpomene Nov 08 '15 at 15:35
  • Our code is pulling five values blackout_host,start_timestamp,stop_timestamp,userid,reason from some flat files in which start_timestamp and start_timestamp time are in epoch and we want to convert it human readable and get the same printed – Newbie Nov 08 '15 at 15:36
  • 3
    I don't think you understand what your code is doing. – melpomene Nov 08 '15 at 15:38
  • elif [[ "${COMMAND}" == 'queryOne' ]] then if [[ "${BLACKOUTHOST}" == '' ]] then blackout_usage exit 1 fi ${MCELL_BIN}/mquery -q -c ${MCELL_ETC}/mclient.conf \ -n "${CS_BLACKOUT_CELL}" -d -f 'csv' \ -a 'CS_EMB_GBF_BLACKOUTS' \ blackout_host,start_timestamp,stop_timestamp,userid,reason' \ -w "blackout_host: == '${BLACKOUTHOST}'" | $MCELL_HOME/mqt.pl |awk -F ',' ' { print $1,echo "from " $2 echo " GMT",echo "to "$3 echo " GMT",echo "by " $4,echo "for " $5 }'\ – Newbie Nov 08 '15 at 15:40
  • @Newbie What is that supposed to be? – Matt Jacob Nov 08 '15 at 15:43
  • @Matt Jacob by your code we are getting testwin1,1446997690,1446998590,kkulka11,testing testwin1,1446997892,1446998792,kkulka111,testing 15 from to Thu Jan 1 05:30:00 1970 by Thu Jan 1 05:30:00 1970 for – Newbie Nov 08 '15 at 15:55
  • @Matt Jacob output should be exactly s that of yours but we are getting above .. – Newbie Nov 08 '15 at 15:56
  • 2
    Then you either didn't copy and paste correctly, or your input isn't what you said it is. You can see the complete input and output in my answer! – Matt Jacob Nov 08 '15 at 16:04
  • The issue that msend_query gives some outeverytime , now how I am getting that print is a query .What should I placed in my _DATA_ value in your logic – Newbie Nov 08 '15 at 16:14
  • You're creating a file, yes? Now you need to open that file, iterate over it line by line, and apply my logic to it, and everything will work. The `__DATA__` section is just for creating a self-contained example. Swap out `` with your actual filehandle (you're opening a file, remember?) and then Bob's your uncle. – Matt Jacob Nov 08 '15 at 16:20
  • 2
    You'll probably also want to order [this book](http://www.amazon.com/gp/product/1449303587) and choose overnight delivery at checkout. – Matt Jacob Nov 08 '15 at 16:21

1 Answers1

-1
while (<DATA>) {
    chomp;

    my @parts = split(/,/, $_);
    $parts[1] = localtime($parts[1]);
    $parts[2] = localtime($parts[2]);

    printf("%s from %s to %s by %s for %s\n", @parts);
}

__DATA__
testingwindows,1446727960,1446728560,kkulka11,testingwin
testingwindows1,1446727160,141228560,kkulka11,testingwin
testingwindows2,1446727120,1446728560,kkulka11,testingwin
testingwindows3,1446727960,1446728560,kkulka11,testingwin

Output:

testingwindows from Thu Nov  5 05:52:40 2015 to Thu Nov  5 06:02:40 2015 by kkulka11 for testingwin
testingwindows1 from Thu Nov  5 05:39:20 2015 to Sun Jun 23 07:09:20 1974 by kkulka11 for testingwin
testingwindows2 from Thu Nov  5 05:38:40 2015 to Thu Nov  5 06:02:40 2015 by kkulka11 for testingwin
testingwindows3 from Thu Nov  5 05:52:40 2015 to Thu Nov  5 06:02:40 2015 by kkulka11 for testingwin

Edit: based on your most recent update to the question, I now believe that you're trying to capture the output of the command and process it. Since you haven't provided a minimal, complete, and verifiable example, and because I have no idea what mquery is and you haven't provided an explanation for that, either, I present to you this guess:

if ($COMMAND eq 'queryone') {
    my @lines = `$MCELL_HOME\\bin\\mquery -q -c $MCELL_HOME\\etc\\mclient.conf -n $CS_BLACKOUT_CELL -d -f csv -a CS_EMB_GBF_BLACKOUTS -s blackout_host,start_timestamp,stop_timestamp,userid,reason -w blackout_host: == '${BLACKOUTHOST}'`;

    for (@lines) {
        chomp;

        my @parts = split(/,/, $_);
        $parts[1] = localtime($parts[1]);
        $parts[2] = localtime($parts[2]);

        printf("%s from %s to %s by %s for %s\n", @parts);
    }       
}
Community
  • 1
  • 1
Matt Jacob
  • 6,503
  • 2
  • 24
  • 27
  • the request was for the timezone abbr to be in the output too – ysth Nov 08 '15 at 15:57
  • 1
    @ysth Good point. He also said "local time" in the subject and then used `gmtime()` in his code, so I really don't have any idea what he wants. – Matt Jacob Nov 08 '15 at 16:02
  • @MattJacob Your output is correct and we need it in similar manner but not sure where we are doing a mistake so it is not coming as desired – Newbie Nov 08 '15 at 16:04
  • Well, I'm not sure either. Maybe you should edit your question to show what you're doing. – Matt Jacob Nov 08 '15 at 16:06
  • Updated the Question with results as per your suggestion but still not received as desired – Newbie Nov 08 '15 at 16:13