in reply to Re^2: extracting value in a string after checking value after colon ':'
in thread extracting value in a string after checking value after colon ':'

secondly if you see the file, there are many lines, i only want to extract the node number (250,251..) only if string cpus: is empty after the colon.

Hope i made my question clear

  • Comment on Re^3: extracting value in a string after checking value after colon ':'

Replies are listed 'Best First'.
Re^4: extracting value in a string after checking value after colon ':'
by Laurent_R (Canon) on Jan 30, 2019 at 09:40 UTC
    i only want to extract the node number (250,251..) only if string cpus: is empty after the colon.
    That's seems to be exactly the output from Athanasius's code. Or, if it is not, then please explain in which respect Athanasius's code does not produce what you want. And also show the code you're using.
Re^4: extracting value in a string after checking value after colon ':'
by poj (Abbot) on Jan 30, 2019 at 09:30 UTC

    How are you reading the lines from the file ?

    #!/usr/bin/perl use strict; use warnings; my $infile = 'infile.txt'; open my $fh,'<',$infile or die "Could not open $infile : $!"; my $lineno = 0; while (<$fh>){ ++$lineno; if (/^ node \s+ (\d+) \s+ \w+ : $ /x){ print "lineno $lineno : $1\n"; } } close $fh; print "$lineno lines read from $infile\n";
    poj