in reply to Simple awk question

Please provide enough of your perl code to show what the variables are, the input, and what you expect the output to look like.

echo $variable | awk '{print $1}'

is redundant. Save yourself some typing.

echo $variable

Okay, you are probably trying to do more than just print a single variable, but that's all I have to go on from what you've given me so far. Well, there's an array called @F and scalars called $time and $error, but it's anyone's guess as to what they contain or what they are for.

1 Peter 4:10

Replies are listed 'Best First'.
Re^2: Simple awk question
by czah7 (Initiate) on Jun 05, 2014 at 18:35 UTC
    So to make it simple.
    #!/usr/bin/perl $error = '2014-06-04T15:24:21-05:00 syslog_dp [0x80e00099][ftp][error] + secure-backup(FBB): trans(5487)'; $time = print $error|print $F[0];
    $time should then = 2014-06-04T15:24:21-05:00
      $time = print $error|print $F[0];

      That attempt to pipe one statement to another statement like you would do when piping shell commands won't work.

      You've already been shown a couple ways to extract the datestamp.

      $error = '2014-06-04T15:24:21-05:00 syslog_dp [0x80e00099][ftp][error] + secure-backup(FBB): trans(5487)'; $time = (split /\s/, $error)[0]; print $time, "\n"; # or you could do this: ($time) = $error =~ /^(\S+)/; print $time, "\n";
        Thanks Fishmonger, that worked! I do appreciate it. However simple it was.

        I may have need of a second request though. Not sure if I should start another thread. But the purpose of this script is to watch a log file, and if it sees an error it emails me. The reason for the timestamp is because I am comparing the time, so If it's an old error I don't get alerted. The problem now is that if it's a continuous error that we are aware of, I still don't want to be alerted every 5-10min(whatever interval i decide to run the script). So I need to write the error it found to a log file. And somehow tell it "if you found this error again, and less than 30min has passed, don't send another alert". Does this make sense?