in reply to extracting value in a string after checking value after colon ':'
Hello t-rex and welcome back!
To match a line in which nothing follows the colon (other than the terminal newline, of course), simply match on :$:
use strict; use warnings; while (<DATA>) { print "$1\n" if / ^ node \s+ (\d+) \s+ \w+ : $ /x; } __DATA__ 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:
Output:
16:43 >perl 1971_SoPW.pl 250 251 252 253 16:44 >
But if whitespace is allowed after the colon, change to:
while (<DATA>) { print "$1\n" if / ^ node \s+ (\d+) \s+ \w+ : \s* $ /x; # ^^^ }
Update: Removed unnecessary chomp from the first code block.
Hope that helps,
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: extracting value in a string after checking value after colon ':'
by t-rex (Scribe) on Jan 30, 2019 at 08:08 UTC | |
by hippo (Archbishop) on Jan 30, 2019 at 09:10 UTC | |
by Laurent_R (Canon) on Jan 30, 2019 at 09:36 UTC | |
by t-rex (Scribe) on Jan 30, 2019 at 08:33 UTC | |
by Laurent_R (Canon) on Jan 30, 2019 at 09:40 UTC | |
by poj (Abbot) on Jan 30, 2019 at 09:30 UTC |