Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: extracting value in a string after checking value after colon ':'

by johngg (Canon)
on Jan 30, 2019 at 17:00 UTC ( [id://1229174]=note: print w/replies, xml ) Need Help??


in reply to extracting value in a string after checking value after colon ':'

You could use a negative look-ahead, i.e. only print the number from the "cpus:" line if the colon is not followed by more space-separated digits.

johngg@shiraz:~/perl/Monks$ perl -Mstrict -Mwarnings -E ' open my $inFH, q{<}, \ <<__EOD__ or die $!; available: 8 nodes (0,8,250-255) node 0 cpus: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 2 +2 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 4 +5 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 6 +8 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 node 0 size: 129733 MB node 0 free: 125997 MB node 8 cpus: 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 1 +05 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 12 +2 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 + 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 +157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 1 +74 175 node 8 size: 129826 MB node 8 free: 126395 MB node 250 cpus: node 250 size: 16128 MB node 250 free: 16127 MB node 251 cpus: node 251 size: 12032 MB node 251 free: 12031 MB node 252 cpus: node 252 size: 16128 MB node 252 free: 16127 MB node 253 cpus: __EOD__ while ( <$inFH> ) { say $1 if m{(?x) ( \d+ ) \s+ cpus: (?! \s* \d) }; } close $inFH or die $!;' 250 251 252 253

I hope this is helpful.

Cheers,

JohnGG

  • Comment on Re: extracting value in a string after checking value after colon ':'
  • Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1229174]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2024-04-20 00:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found