in reply to Regular expression help

Hi,

my quick and dirty proposal:

#!/usr/bin/perl use strict; use warnings FATAL => qw(all); my @lines = ( 'brown vihl729 172.31.176.71:8532503_6 (v2013.02) (elicserv1.muc.i +fin.com/3120 6260), start Mon 3/11 18:31', 'stephen blrl267 172.20.150.73:233707_1 (v2) (elicserv2.muc.ifin.c +om/3120 4789), start Tue 3/12 6:32 ', 'martin vihlc295 172.31.176.73:33228361_1 (v2012.11) (elicserv1.mu +c.ifin.com/3120 4152), start Wed 3/6 12:08 ', ); foreach my $line (@lines) { my ($user, $d1, $d2, $version, $server, $d3, $s, $date) = split /\ +s+/, $line, 8; for ($version, $server) { s/^\(//; s/\)$//; s#/.+$##; } print "user: $user version: $version server: $server date: $ +date\n"; }

Best regards
McA

Replies are listed 'Best First'.
Re^2: Regular expression help
by ghosh123 (Monk) on Mar 12, 2013 at 08:54 UTC

    This is fine. thanks. But I need it in regular expression.

      What had you tried?

      But I need it in regular expression..
      So, McA solution is using what? Please show what you have done on your own.
      The result you are getting and what is expected.
      Thanks

      If you tell me, I'll forget.
      If you show me, I'll remember.
      if you involve me, I'll understand.
      --- Author unknown to me

        Well the problem is a bit more complicated. The solution McA has given certainly works.

        Lets say in the loop, I first grep it for a particular user say, stephen by the following expression ,although the later part of this expression needs to be corrected for the server name and etc

        if(/^\s+stephen(.*)/)

        And , now for the subsequent iteration, I want to grep all the user names and servername,version name for other users who are not stephen. That is becoming a problem to uniquely identify the lines for which the user name is not known. So using split is a problem. Can't I have a regular expression of the following pattern :
        $line =~ /^\s+(any user but stephen) (machine name) (version)(server)(date time )/
        Hope I could explain the problem.
        Thanks.

      "But I need it in regular expression"

      So take this one to continue:

      Update: For some unknown reason i skipped a column, sorry:

      #!/usr/bin/env perl my $line = 'brown vihl729 172.31.176.71:8532503_6 (v2013.02) (elicserv +1.muc.ifin.com/3120 6260), start Mon 3/11 18:31'; $line =~ m/(\w+)\s ([0-9a-z]+)\s [0-9.:()_]+\s \(.+\)\s \(([a-z0-9.]+).+\) ,\s [\w\s]+ (\d+\/\d+\s\d+:\d+) /x; print qq($1 $2 $3 $4\n); __END__ Karls-Mac-mini:monks karl$ ./missing.pl brown vihl729 elicserv1.muc.ifin.com 3/11 18:31

      (If something still makes sense...)

      Karl

      «The Crux of the Biscuit is the Apostrophe»