Quantcast
Channel: UNIX and Linux Forums
Viewing all articles
Browse latest Browse all 16232

Extract the word from the file and print it

$
0
0
I have a file which I am reading and then I need to extract a particualr word and if it matches the line.
Code:

2015-01-22 07:30:17,814000 +0900 [29133:main]/INFO:[configuration.manager/Cont'd_0031] -            <ns2:virtualServerid="PH11PK" />
Means if the line contain Virtual server I need to extract the id .

Code I wrote
Code:

#!/usr/bin/perl

#@filename = 'file.txt';
$VS=@_;
$1;

open (FILE, "file.txt") or die;

while (my $line= <FILE>) {
#foreach  $line (@filename)
  {
      if ($line =~ /Info : \[([a-zA-Z]+)\] - [([a-zA-Z]+)\]\/) {
        print ("Login successful for ID $2\n");
        $VS++;
      }
      else{
      print ("ID $2 not connected,please check!!");
    }

But it is not working


Moderator's Comments:
Please wrap all code, files, input & output/errors in CODE tags
It makes them far easier to read and preserves multiple spaces

Viewing all articles
Browse latest Browse all 16232

Trending Articles