I have an express API and I want to show the api memory usage, to test the solution, I create a global variable in the module and for each get request I PUSH a data to the array to see if memory increase or no
let array = [];
const randomData = `150 216 86 129 25 116 72 20 155 148 91 30 187 152 136 204 125 182 250
217 97 45 161 48 223 1 55 163 236 240 179 118 234 175 71 56 44 221 245 59 145 66 173 1
12 197 88 146 140 111 223 59 169 53 68 123 0 252 68 96 215 132 236 245 128 43 98 16 110
22 5 179 12 177 87 162 5 134 64 226 250 70 238 114 215 135 147 85 218 140 194 244 107 62
87 19 169 227 2 97 184 215 164 30 34 229 35 46 71 127 120 75 243 68 143 40 203 132 211 212
253 136 159 24 149 241 58 167 199 247 140 229 151 85 65 25 44 106 199 216 110 61 72 135
103 251 122 103 128 134 9 25 38 61 136 159 158 225 137 44 246 176 217 202 149 73 111 73 22
41 151 217 59 69 10 143 85 181 10 194 64 23 244 243 179 240 150 25 111 162 60 221 197 36 191
138 217 185 1 127 226 152 75 7 250 72 147 242 184 70 158 211 154 225 165 130 57 24 50 97 192
125 88 131 183 171 67 209 251 151 64 11 59 206 75 143 17 34 203 95 97 57 209 212 112 99 180
136 142 230 163 82 172 232 134 135 50 101 144 75 94 145 236 206 182 124 120 95 225 144 31 79
75 27 214 115 37 25 122 6 106 26 66 145 135 73 22 53 13 57 202 129 61 42 207 138 143 170 241
`;
exports.getAPIHealth = function (req, res) {
console.log(process.memoryUsage())
const memoryUsedMB = process.memoryUsage().heapUsed / (1024 * 1024);
console.log(memoryUsedMB);
array.push(randomData.toString());
res.status(200).json({
live: true,
memoryUsage: memoryUsedMB.toFixed(2) + ' MB'
})
};
In fact when I run this example I got strange values:
{ rss: 57921536,
heapTotal: 57929728,
heapUsed: 18556128,
external: 655899 }
17.73406219482422
{ rss: 58200064,
heapTotal: 57929728,
heapUsed: 18717496,
external: 655899 }
17.854393005371094
{ rss: 58200064,
heapTotal: 57929728,
heapUsed: 18760720,
external: 655899 }
17.894927978515625
{ rss: 58200064,
heapTotal: 57929728,
heapUsed: 18797824,
external: 655899 }
17.930313110351562
{ rss: 58220544,
heapTotal: 57929728,
heapUsed: 18834928,
external: 655899 }
17.965728759765625
{ rss: 41418752,
heapTotal: 25423872,
heapUsed: 18512640,
external: 153782 }
17.659194946289062
memory increase for each request (and this is normal) but at certain point it decrease,
can any one tell me why I have this behavior ?
NB: I notice that memory usage never reach 18MB (even after many requests)
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I am having a string of pixels of a B/W image in this manner:-
48 34 21 18 16 21 26 36 40...44 53 57 64 82 95 9
of string length 547, and I want these pixels to be converted into an image of 48*48 pixel B/W image.
Is there any python library or PyTorch function to make it possible?
Link to the Notebook
You can use PIL.Image.frombuffer() function for example.
from PIL import Image
pixels = '126 126 129 120 110 168 174 172 173 174 170 157 134 97 78 75 118 119 97 117 142 86 58 71 124 161 162 134 100 119 124 118 153 135 143 180 180 172 153 128 98 67 60 75 85 89 85 98 123 126 131 119 119 172 180 171 155 127 100 82 77 72 54 97 184 151 157 176 125 74 71 114 173 171 136 109 116 118 118 150 152 150 178 191 188 187 180 169 152 127 86 60 74 91 92 95 119 131 127 115 113 153 130 94 71 62 65 69 83 95 79 137 181 174 196 148 88 75 103 149 135 107 100 105 104 112 140 162 178 191 187 181 171 166 159 156 159 155 144 97 54 69 83 91 112 116 100 85 74 73 59 58 67 75 74 80 104 110 96 153 180 182 151 100 103 139 167 172 152 141 135 135 141 163 182 191 191 183 179 169 144 127 132 147 156 154 152 143 92 52 56 78 97 86 69 60 51 48 55 65 74 74 71 92 121 122 115 155 177 166 151 158 181 200 201 208 207 198 187 181 182 189 187 187 179 170 154 119 91 86 101 124 139 154 153 153 132 73 51 60 63 52 48 45 46 54 65 78 79 86 96 131 163 146 133 162 179 193 202 211 205 208 216 218 209 204 191 183 184 183 176 170 153 127 96 98 127 148 148 142 134 140 150 154 149 102 49 53 57 58 65 68 70 75 75 74 90 121 151 176 176 148 156 170 193 209 215 211 203 213 219 212 206 201 183 174 173 166 162 135 101 86 99 147 176 175 166 164 157 146 148 155 154 128 55 53 54 54 77 92 89 68 58 61 69 94 143 171 155 150 161 163 185 197 203 202 207 213 212 209 202 195 176 163 157 153 125 83 86 118 160 179 172 165 161 161 166 164 155 155 153 138 74 54 40 70 110 122 106 92 112 123 116 108 96 94 118 146 155 159 166 174 180 187 198 213 216 205 196 192 178 155 139 117 88 96 131 163 159 142 130 126 123 123 132 139 147 156 158 145 75 59 60 117 163 157 138 157 176 179 186 189 167 121 98 105 123 149 161 162 165 178 196 213 214 199 188 181 171 147 117 97 104 124 134 127 123 131 135 139 138 137 144 146 139 147 135 106 75 69 98 155 184 180 178 189 187 182 181 190 203 198 165 126 102 109 138 162 171 193 216 225 222 204 191 182 154 130 116 118 137 143 125 108 100 96 96 102 122 129 145 158 142 96 90 127 88 50 125 175 195 191 191 189 178 166 165 172 175 178 177 162 139 116 112 130 158 194 211 216 218 202 189 165 132 129 134 143 129 104 86 98 80 90 128 97 70 90 117 149 161 109 127 151 112 58 145 187 200 198 192 185 174 171 180 162 135 117 120 126 128 128 124 116 124 157 171 166 156 126 107 92 101 127 129 104 93 105 119 137 113 136 145 136 118 107 119 149 162 147 152 152 125 77 142 183 189 176 177 178 174 163 118 109 118 109 95 83 94 101 114 134 125 120 152 153 154 152 156 124 99 103 122 111 112 136 151 156 163 160 160 163 155 143 145 159 163 137 141 147 126 86 119 158 161 184 183 185 163 100 98 167 135 126 89 99 116 104 101 146 144 115 162 197 201 191 189 156 112 94 103 108 112 127 141 150 153 155 156 148 141 149 156 157 165 155 144 146 129 86 112 140 156 191 190 179 144 126 159 179 160 150 148 143 135 127 135 138 137 117 151 199 195 178 177 169 123 105 100 106 115 132 138 143 145 145 143 139 149 156 156 151 141 141 143 143 130 94 131 136 142 181 198 188 177 189 193 185 183 166 152 136 123 121 130 125 132 143 186 207 192 177 177 169 140 119 128 141 142 147 154 159 158 155 158 156 153 146 132 114 122 136 136 134 127 105 136 143 151 167 184 190 198 189 175 168 160 148 138 131 131 144 160 181 176 168 212 206 202 198 185 173 160 150 133 139 148 155 158 164 165 158 146 133 119 113 118 127 130 127 126 125 124 113 176 181 163 183 177 177 184 186 183 172 164 160 160 164 165 174 189 184 171 206 218 212 206 198 187 180 177 171 157 125 113 116 121 127 126 126 126 129 133 136 134 128 121 118 117 115 113 111 175 199 166 177 196 190 188 189 190 190 188 186 184 182 183 189 179 150 171 208 219 209 201 191 181 173 167 152 150 159 157 148 149 154 155 157 153 146 142 140 130 124 117 112 113 108 100 104 175 199 190 163 181 191 187 187 191 191 189 185 179 170 161 155 150 168 168 185 221 204 193 181 168 165 157 137 120 126 158 167 164 168 168 166 160 152 147 144 138 127 118 113 106 103 95 95 173 196 200 206 189 175 168 169 171 167 166 159 154 155 162 176 190 172 147 191 213 202 193 179 162 158 154 137 124 108 123 155 163 167 169 167 164 157 151 144 135 128 120 113 106 99 92 89 164 192 203 215 214 208 206 193 183 175 173 176 179 185 194 196 182 142 148 202 213 204 202 187 173 165 154 151 135 112 102 131 154 157 162 161 158 149 142 137 129 123 117 108 101 95 88 85 156 189 205 211 206 206 206 202 197 198 194 197 201 201 195 178 156 129 171 211 216 214 208 190 179 171 168 149 132 117 102 112 134 152 154 150 150 143 137 131 123 119 112 103 96 91 83 84 148 189 202 204 201 198 199 201 202 201 197 194 192 191 177 159 133 136 189 206 208 210 199 186 180 176 161 129 129 117 106 114 126 144 149 149 145 141 135 130 122 116 108 98 93 90 81 83 149 190 200 199 194 196 199 194 193 192 185 182 180 172 161 141 129 159 188 186 193 194 185 176 173 164 123 93 105 104 117 127 125 132 145 149 142 137 134 129 119 111 103 96 92 87 79 83 159 190 197 198 190 188 188 186 182 180 174 169 165 160 145 126 134 180 187 154 158 186 175 154 151 137 99 84 87 101 124 130 131 131 140 146 143 136 133 126 117 109 99 92 88 85 76 80 171 189 192 187 184 182 182 179 173 169 168 160 156 148 135 124 158 191 196 172 158 169 146 126 123 117 103 102 104 114 128 132 135 133 133 143 144 138 130 122 112 104 96 90 87 84 76 73 175 190 184 180 178 173 171 169 167 162 159 156 152 139 123 131 177 189 192 188 177 167 147 122 111 101 100 110 116 117 131 133 133 135 134 140 144 138 129 117 108 103 97 95 92 85 76 69 179 191 186 178 171 168 164 162 156 151 153 150 144 131 118 151 181 191 198 193 183 175 163 136 112 109 115 118 121 126 136 132 130 132 129 137 144 140 127 116 108 105 101 99 92 86 76 67 160 190 184 173 169 161 156 152 148 144 146 147 141 120 126 172 184 195 203 200 191 184 174 159 142 139 133 129 133 138 135 131 124 124 127 130 141 145 132 119 112 109 106 104 96 88 73 64 110 184 188 176 168 158 145 143 144 147 146 146 136 115 145 176 184 198 199 196 197 190 178 163 159 157 149 145 144 141 134 129 121 119 126 128 138 151 141 124 117 113 110 106 98 88 69 60 89 172 189 178 170 163 149 138 144 152 155 154 128 128 166 178 184 193 197 200 198 192 182 170 163 168 162 156 147 140 136 132 121 115 118 124 130 155 152 132 126 118 110 106 98 86 66 56 60 157 186 180 173 167 153 142 155 167 166 156 125 151 174 178 178 185 193 189 191 188 175 168 167 162 144 130 126 122 122 124 118 112 117 121 124 155 163 137 129 118 110 107 104 86 63 57 41 140 184 178 178 170 159 154 172 183 181 158 134 161 170 176 176 184 184 169 156 138 129 134 136 114 101 99 100 99 99 98 103 108 119 128 131 160 171 140 126 113 106 112 108 82 64 60 39 116 184 173 179 171 165 161 182 199 198 170 149 170 170 174 185 173 148 132 123 122 126 120 106 109 124 129 124 97 64 61 58 78 112 130 136 165 177 143 121 106 104 124 107 75 63 60 40 86 181 175 176 175 169 162 175 203 203 179 164 179 175 172 143 109 97 84 106 158 175 184 171 164 168 134 76 43 33 65 86 90 105 122 142 174 175 134 116 98 119 135 99 70 60 59 48 69 169 183 173 174 170 164 169 197 209 190 164 179 170 142 130 126 79 44 55 82 127 142 124 112 105 72 54 71 89 111 102 88 96 120 149 180 163 127 110 100 136 126 84 60 57 60 50 59 146 190 174 173 174 168 167 189 204 199 175 164 150 145 168 171 143 111 125 135 144 135 133 139 136 129 128 128 126 112 85 78 102 128 155 174 141 127 100 119 144 114 73 58 60 62 50 50 118 189 181 173 175 171 167 180 196 194 181 166 162 161 163 151 155 164 168 166 164 155 155 155 148 141 135 124 105 85 78 90 122 138 156 149 140 124 98 140 138 94 64 60 63 64 47 48 80 170 191 177 174 180 172 169 187 189 177 170 172 172 169 159 148 142 141 140 139 137 139 133 125 116 106 96 86 81 88 113 122 127 135 142 155 102 119 154 118 76 62 68 65 65 39 46 52 130 185 185 174 182 178 170 174 186 178 171 176 187 178 164 151 135 121 115 118 121 116 110 104 99 93 92 92 93 111 127 125 137 138 161 126 94 144 139 96 70 69 71 61 74 35 40 44 84 166 188 183 176 180 178 174 179 185 180 193 193 180 171 160 150 151 154 152 151 146 141 135 119 108 101 96 102 128 137 145 144 133 126 91 118 147 117 82 74 78 72 61 101 38 36 44 53 127 181 187 178 174 181 180 173 183 190 190 196 195 178 164 161 167 172 168 165 171 163 154 141 128 115 104 117 149 155 139 124 111 96 99 139 135 102 88 86 82 72 64 140 43 37 41 43 75 161 181 183 173 174 179 180 175 190 199 197 198 189 181 173 166 171 173 180 176 158 148 141 126 115 113 129 147 136 132 115 97 91 125 148 124 105 94 87 77 66 82 181 44 41 35 41 45 114 177 177 181 177 175 183 184 176 192 198 184 186 195 198 188 173 174 172 167 157 145 138 121 121 115 113 125 146 133 98 83 111 148 145 122 107 90 85 75 58 118 203 48 44 35 36 42 58 144 181 189 188 182 182 187 181 172 180 189 192 193 198 192 186 178 165 160 152 138 128 128 129 110 111 139 132 105 83 97 143 153 137 118 97 87 79 68 68 168 211 45 45 41 32 38 40 90 163 179 190 184 186 185 189 182 176 185 194 199 187 175 173 162 156 156 145 128 125 127 121 104 111 121 110 89 87 131 153 148 130 106 85 77 71 60 107 199 208'
b = bytes(int(p) for p in pixels.split())
i = Image.frombuffer('L', (48, 48), b)
print(i)
i.save('example.png')
Outputs example.png:
Yun can also use numpy to read the fixed-length data and save to image with cv2.
import numpy as np
import cv2
pixels = '126 126 129 120 110 168 174 172 173 174 170 157 134 97 78 75 118 119 97 117 142 86 58 71 124 161 162 134 100 119 124 118 153 135 143 180 180 172 153 128 98 67 60 75 85 89 85 98 123 126 131 119 119 172 180 171 155 127 100 82 77 72 54 97 184 151 157 176 125 74 71 114 173 171 136 109 116 118 118 150 152 150 178 191 188 187 180 169 152 127 86 60 74 91 92 95 119 131 127 115 113 153 130 94 71 62 65 69 83 95 79 137 181 174 196 148 88 75 103 149 135 107 100 105 104 112 140 162 178 191 187 181 171 166 159 156 159 155 144 97 54 69 83 91 112 116 100 85 74 73 59 58 67 75 74 80 104 110 96 153 180 182 151 100 103 139 167 172 152 141 135 135 141 163 182 191 191 183 179 169 144 127 132 147 156 154 152 143 92 52 56 78 97 86 69 60 51 48 55 65 74 74 71 92 121 122 115 155 177 166 151 158 181 200 201 208 207 198 187 181 182 189 187 187 179 170 154 119 91 86 101 124 139 154 153 153 132 73 51 60 63 52 48 45 46 54 65 78 79 86 96 131 163 146 133 162 179 193 202 211 205 208 216 218 209 204 191 183 184 183 176 170 153 127 96 98 127 148 148 142 134 140 150 154 149 102 49 53 57 58 65 68 70 75 75 74 90 121 151 176 176 148 156 170 193 209 215 211 203 213 219 212 206 201 183 174 173 166 162 135 101 86 99 147 176 175 166 164 157 146 148 155 154 128 55 53 54 54 77 92 89 68 58 61 69 94 143 171 155 150 161 163 185 197 203 202 207 213 212 209 202 195 176 163 157 153 125 83 86 118 160 179 172 165 161 161 166 164 155 155 153 138 74 54 40 70 110 122 106 92 112 123 116 108 96 94 118 146 155 159 166 174 180 187 198 213 216 205 196 192 178 155 139 117 88 96 131 163 159 142 130 126 123 123 132 139 147 156 158 145 75 59 60 117 163 157 138 157 176 179 186 189 167 121 98 105 123 149 161 162 165 178 196 213 214 199 188 181 171 147 117 97 104 124 134 127 123 131 135 139 138 137 144 146 139 147 135 106 75 69 98 155 184 180 178 189 187 182 181 190 203 198 165 126 102 109 138 162 171 193 216 225 222 204 191 182 154 130 116 118 137 143 125 108 100 96 96 102 122 129 145 158 142 96 90 127 88 50 125 175 195 191 191 189 178 166 165 172 175 178 177 162 139 116 112 130 158 194 211 216 218 202 189 165 132 129 134 143 129 104 86 98 80 90 128 97 70 90 117 149 161 109 127 151 112 58 145 187 200 198 192 185 174 171 180 162 135 117 120 126 128 128 124 116 124 157 171 166 156 126 107 92 101 127 129 104 93 105 119 137 113 136 145 136 118 107 119 149 162 147 152 152 125 77 142 183 189 176 177 178 174 163 118 109 118 109 95 83 94 101 114 134 125 120 152 153 154 152 156 124 99 103 122 111 112 136 151 156 163 160 160 163 155 143 145 159 163 137 141 147 126 86 119 158 161 184 183 185 163 100 98 167 135 126 89 99 116 104 101 146 144 115 162 197 201 191 189 156 112 94 103 108 112 127 141 150 153 155 156 148 141 149 156 157 165 155 144 146 129 86 112 140 156 191 190 179 144 126 159 179 160 150 148 143 135 127 135 138 137 117 151 199 195 178 177 169 123 105 100 106 115 132 138 143 145 145 143 139 149 156 156 151 141 141 143 143 130 94 131 136 142 181 198 188 177 189 193 185 183 166 152 136 123 121 130 125 132 143 186 207 192 177 177 169 140 119 128 141 142 147 154 159 158 155 158 156 153 146 132 114 122 136 136 134 127 105 136 143 151 167 184 190 198 189 175 168 160 148 138 131 131 144 160 181 176 168 212 206 202 198 185 173 160 150 133 139 148 155 158 164 165 158 146 133 119 113 118 127 130 127 126 125 124 113 176 181 163 183 177 177 184 186 183 172 164 160 160 164 165 174 189 184 171 206 218 212 206 198 187 180 177 171 157 125 113 116 121 127 126 126 126 129 133 136 134 128 121 118 117 115 113 111 175 199 166 177 196 190 188 189 190 190 188 186 184 182 183 189 179 150 171 208 219 209 201 191 181 173 167 152 150 159 157 148 149 154 155 157 153 146 142 140 130 124 117 112 113 108 100 104 175 199 190 163 181 191 187 187 191 191 189 185 179 170 161 155 150 168 168 185 221 204 193 181 168 165 157 137 120 126 158 167 164 168 168 166 160 152 147 144 138 127 118 113 106 103 95 95 173 196 200 206 189 175 168 169 171 167 166 159 154 155 162 176 190 172 147 191 213 202 193 179 162 158 154 137 124 108 123 155 163 167 169 167 164 157 151 144 135 128 120 113 106 99 92 89 164 192 203 215 214 208 206 193 183 175 173 176 179 185 194 196 182 142 148 202 213 204 202 187 173 165 154 151 135 112 102 131 154 157 162 161 158 149 142 137 129 123 117 108 101 95 88 85 156 189 205 211 206 206 206 202 197 198 194 197 201 201 195 178 156 129 171 211 216 214 208 190 179 171 168 149 132 117 102 112 134 152 154 150 150 143 137 131 123 119 112 103 96 91 83 84 148 189 202 204 201 198 199 201 202 201 197 194 192 191 177 159 133 136 189 206 208 210 199 186 180 176 161 129 129 117 106 114 126 144 149 149 145 141 135 130 122 116 108 98 93 90 81 83 149 190 200 199 194 196 199 194 193 192 185 182 180 172 161 141 129 159 188 186 193 194 185 176 173 164 123 93 105 104 117 127 125 132 145 149 142 137 134 129 119 111 103 96 92 87 79 83 159 190 197 198 190 188 188 186 182 180 174 169 165 160 145 126 134 180 187 154 158 186 175 154 151 137 99 84 87 101 124 130 131 131 140 146 143 136 133 126 117 109 99 92 88 85 76 80 171 189 192 187 184 182 182 179 173 169 168 160 156 148 135 124 158 191 196 172 158 169 146 126 123 117 103 102 104 114 128 132 135 133 133 143 144 138 130 122 112 104 96 90 87 84 76 73 175 190 184 180 178 173 171 169 167 162 159 156 152 139 123 131 177 189 192 188 177 167 147 122 111 101 100 110 116 117 131 133 133 135 134 140 144 138 129 117 108 103 97 95 92 85 76 69 179 191 186 178 171 168 164 162 156 151 153 150 144 131 118 151 181 191 198 193 183 175 163 136 112 109 115 118 121 126 136 132 130 132 129 137 144 140 127 116 108 105 101 99 92 86 76 67 160 190 184 173 169 161 156 152 148 144 146 147 141 120 126 172 184 195 203 200 191 184 174 159 142 139 133 129 133 138 135 131 124 124 127 130 141 145 132 119 112 109 106 104 96 88 73 64 110 184 188 176 168 158 145 143 144 147 146 146 136 115 145 176 184 198 199 196 197 190 178 163 159 157 149 145 144 141 134 129 121 119 126 128 138 151 141 124 117 113 110 106 98 88 69 60 89 172 189 178 170 163 149 138 144 152 155 154 128 128 166 178 184 193 197 200 198 192 182 170 163 168 162 156 147 140 136 132 121 115 118 124 130 155 152 132 126 118 110 106 98 86 66 56 60 157 186 180 173 167 153 142 155 167 166 156 125 151 174 178 178 185 193 189 191 188 175 168 167 162 144 130 126 122 122 124 118 112 117 121 124 155 163 137 129 118 110 107 104 86 63 57 41 140 184 178 178 170 159 154 172 183 181 158 134 161 170 176 176 184 184 169 156 138 129 134 136 114 101 99 100 99 99 98 103 108 119 128 131 160 171 140 126 113 106 112 108 82 64 60 39 116 184 173 179 171 165 161 182 199 198 170 149 170 170 174 185 173 148 132 123 122 126 120 106 109 124 129 124 97 64 61 58 78 112 130 136 165 177 143 121 106 104 124 107 75 63 60 40 86 181 175 176 175 169 162 175 203 203 179 164 179 175 172 143 109 97 84 106 158 175 184 171 164 168 134 76 43 33 65 86 90 105 122 142 174 175 134 116 98 119 135 99 70 60 59 48 69 169 183 173 174 170 164 169 197 209 190 164 179 170 142 130 126 79 44 55 82 127 142 124 112 105 72 54 71 89 111 102 88 96 120 149 180 163 127 110 100 136 126 84 60 57 60 50 59 146 190 174 173 174 168 167 189 204 199 175 164 150 145 168 171 143 111 125 135 144 135 133 139 136 129 128 128 126 112 85 78 102 128 155 174 141 127 100 119 144 114 73 58 60 62 50 50 118 189 181 173 175 171 167 180 196 194 181 166 162 161 163 151 155 164 168 166 164 155 155 155 148 141 135 124 105 85 78 90 122 138 156 149 140 124 98 140 138 94 64 60 63 64 47 48 80 170 191 177 174 180 172 169 187 189 177 170 172 172 169 159 148 142 141 140 139 137 139 133 125 116 106 96 86 81 88 113 122 127 135 142 155 102 119 154 118 76 62 68 65 65 39 46 52 130 185 185 174 182 178 170 174 186 178 171 176 187 178 164 151 135 121 115 118 121 116 110 104 99 93 92 92 93 111 127 125 137 138 161 126 94 144 139 96 70 69 71 61 74 35 40 44 84 166 188 183 176 180 178 174 179 185 180 193 193 180 171 160 150 151 154 152 151 146 141 135 119 108 101 96 102 128 137 145 144 133 126 91 118 147 117 82 74 78 72 61 101 38 36 44 53 127 181 187 178 174 181 180 173 183 190 190 196 195 178 164 161 167 172 168 165 171 163 154 141 128 115 104 117 149 155 139 124 111 96 99 139 135 102 88 86 82 72 64 140 43 37 41 43 75 161 181 183 173 174 179 180 175 190 199 197 198 189 181 173 166 171 173 180 176 158 148 141 126 115 113 129 147 136 132 115 97 91 125 148 124 105 94 87 77 66 82 181 44 41 35 41 45 114 177 177 181 177 175 183 184 176 192 198 184 186 195 198 188 173 174 172 167 157 145 138 121 121 115 113 125 146 133 98 83 111 148 145 122 107 90 85 75 58 118 203 48 44 35 36 42 58 144 181 189 188 182 182 187 181 172 180 189 192 193 198 192 186 178 165 160 152 138 128 128 129 110 111 139 132 105 83 97 143 153 137 118 97 87 79 68 68 168 211 45 45 41 32 38 40 90 163 179 190 184 186 185 189 182 176 185 194 199 187 175 173 162 156 156 145 128 125 127 121 104 111 121 110 89 87 131 153 148 130 106 85 77 71 60 107 199 208'
a = list(map(int, pixels.split(' ')))[:48 * 48]
i = np.array(a).reshape((48, 48)).astype('uint8')
cv2.imwrite('a.png', i)
Outputs a.png.
enter image description here
I have a huge dataset with ID, MEAN, and DATE (in day of the year). I'm sub-setting it below just for example:
OBJECTID MEAN DATE
1 0.960337524 27
2 1.024530873 27
3 1.07565201 27
4 1.32608937 27
5 1.115863256 27
6 0.738648832 27
7 1.209547088 27
8 1.190287749 27
1 1.311272704 43
2 1.421150386 43
3 1.341622942 43
4 1.343600738 43
5 1.322288454 43
6 1.057037145 43
7 1.262514248 43
8 1.148541133 43
1 1.141311572 75
2 1.12654984 75
3 1.125632558 75
4 1.128487158 75
5 1.181200445 75
6 0.820567181 75
7 0.973662794 75
8 0.903646102 75
In this example, the first date is DAY 27 (Jan 27th). I want to reformat this in Excel so DATE is the horizontal header and ID is the first vertical column like this:
OBJECTID 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 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 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365
1
2
3
4
5
6
7
8
How do I use INDEX and MATCH to populate the cells in the blank table above with the values in the dataset? Not all dates in the table will have a value so I need it to populate it with zero like this:
OBJECTID 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 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 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.960337524 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1.311272704 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1.141311572 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
2
3
4
5
6
7
8
This is what I came up with so far:
=IFERROR(INDEX($B$2:$B$2617, MATCH(0, COUNTIF($E2:E2,$B$2:$B$2617)+IF($A$2:$A$2617<>$E2, 1, 0), 0)), 0)
But it doesn't account for the dates with no values. It put the MEAN value for Day 27 into the cell for Day 1.
OBJECTID MEAN DATE OBJECTID 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 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 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365
1 0.960337524 27 1 0.960337524
2 1.024530873 27 2
3 1.07565201 27 3
4 1.32608937 27 4
5 1.115863256 27 5
6 0.738648832 27 6
7 1.209547088 27 7
8 1.190287749 27 8
1 1.311272704 43
2 1.421150386 43
3 1.341622942 43
4 1.343600738 43
5 1.322288454 43
6 1.057037145 43
7 1.262514248 43
8 1.148541133 43
1 1.141311572 75
2 1.12654984 75
3 1.125632558 75
4 1.128487158 75
5 1.181200445 75
6 0.820567181 75
7 0.973662794 75
8 0.903646102 75
Any advice or push in the right direction would be appreciated!
On condition that there is only one Mean in your data for each combination of ID and Date the formula below will do the job. (Input is the sheet with your data in it.)
=SUMIFS(Input!$B$2:$B$2617,Input!$A$2:$A$2617,$A2,Input!$C$2:$C$2617,B$1)
However, this formula makes the range management too error prone. Luckily most errors in the range setting will result in a formula error but the process can be much simplified by separating range management from data extraction.
I assigned the name Data to the range Input!$A$2:$C$2617. In fact, you would probably construct this range to be dynamic so that it adjusts to the number of data rows you have automatically. But that is an extra benefit of properly managing ranges which is outside the scope of your present question.
Use the range Data in the above formula you arrive at this:-
=SUMIFS(INDEX(Data,,2),INDEX(Data,,1),$A2,INDEX(Data,,3),B$1)
Either this formula or the one first above introduced can be copied to the right and down to cover your entire output table. If they bother you (as they did me) you can suppress the display of zeros in the sheet or in each cell, using the sheet settings or the cell format to do so.
What you can do is create another unique ID using simple "&" (concat) function. Basically add a 4th column which has the formula
=A2&"_"&C2
The above takes the assumption that your first entry is in 2nd row and this formula is for 2nd row as well which you can drag. Once done then you can apply index match on this new ID.
Hope it helps in clearing your query.
When I am trying to provide a large input, it is truncating to a specific number.
eg. If I input around 50k-100k inputs(156 repeated number of times), its truncates to 1023. But when I provide input around 200k(shown below), it truncates to 1187.
if __name__ == '__main__':
iplist = list(map(int, input().rstrip().split()))
print("len of exp: ",len(iplist))
1) provide very large input:
eg. below is 1686 numbers input , but if you run the above code, it says length is : 1187:
Seems there is some character limit in shell as if I change a few numbers from 3 digit to 2 digit, or 1 digit, this length increases
0 82 180 55 168 41 179 59 139 71 6 12 135 139 73 157 4 74 195 60 45 28 67 136 58 55 22 60 33 84 48 185 118 29 41 86 22 172 145 114 43 103 126 130 43 152 87 199 26 34 59 24 63 79 160 73 86 134 133 71 18 182 57 89 163 98 175 137 70 73 3 113 176 130 43 19 34 83 170 12 117 30 36 132 61 197 5 99 131 91 171 102 25 28 143 188 126 118 77 148 143 81 61 120 163 56 91 149 91 62 161 161 44 198 93 57 195 51 156 78 142 127 132 119 107 75 59 33 146 136 133 89 169 146 161 84 3 5 33 46 67 195 7 63 193 53 120 140 56 28 170 150 156 103 69 63 178 128 49 124 64 182 166 186 129 79 70 84 84 104 82 103 51 42 166 44 95 38 136 103 67 106 53 175 161 122 190 140 50 39 16 66 174 134 52 55 14 123 91 98 179 173 2 30 15 120 26 62 159 114 165 178 172 18 153 134 140 143 26 142 135 42 9 61 129 61 68 143 136 159 193 67 132 195 49 100 68 27 114 27 141 80 157 66 50 110 0 191 5 26 133 92 20 142 105 149 156 173 44 44 84 38 112 169 185 113 69 53 141 183 32 34 15 189 100 66 51 52 9 57 78 94 101 51 37 159 152 145 132 197 189 17 187 53 138 172 167 159 26 108 142 58 94 110 48 195 176 51 47 137 108 78 31 162 129 20 121 33 165 5 182 107 174 169 112 112 142 79 71 120 139 166 178 34 76 178 181 4 30 28 93 90 58 124 4 139 145 125 173 62 131 155 121 57 125 34 170 19 65 41 139 5 159 69 191 187 0 172 143 182 152 36 24 163 161 29 102 58 154 27 120 37 183 194 95 60 28 17 79 93 10 170 50 170 39 193 157 191 117 101 173 22 89 198 185 50 27 87 108 133 115 181 123 50 175 170 62 155 187 141 0 197 63 3 119 102 196 29 46 66 82 19 88 171 169 73 22 196 112 82 82 179 15 157 181 142 127 43 97 66 136 50 15 199 53 135 54 1 116 100 67 198 119 155 121 89 180 95 37 93 178 71 24 145 28 6 88 107 1 137 173 138 139 141 137 192 28 191 146 144 43 13 94 163 169 15 4 101 111 193 146 41 17 171 138 197 129 178 105 130 116 30 68 7 171 158 152 151 149 98 95 193 111 141 108 32 157 64 134 20 57 80 61 26 3 199 24 132 178 129 63 46 111 83 53 35 41 5 186 143 55 34 88 119 175 148 151 132 12 37 104 21 70 165 48 25 117 72 158 47 153 173 93 16 56 98 51 50 56 38 193 63 24 81 182 199 29 134 84 193 123 188 166 145 106 14 171 23 38 129 22 143 54 67 160 62 165 11 112 173 1 105 37 25 138 19 25 119 105 61 64 181 49 31 126 155 45 97 130 36 178 152 179 32 19 139 47 137 151 159 62 152 17 51 130 107 23 155 27 128 168 91 109 17 74 188 125 120 85 7 108 16 160 87 48 131 27 95 20 130 7 35 34 24 86 164 131 109 71 110 190 39 154 99 9 28 39 134 100 125 93 8 141 5 96 141 137 75 189 109 157 196 144 143 172 31 60 103 92 83 166 82 75 120 134 84 148 173 170 1 98 63 9 191 69 57 133 158 84 74 19 41 70 164 137 42 147 197 97 39 80 63 122 155 135 56 191 36 29 113 37 80 129 46 71 150 56 156 108 140 30 127 134 100 43 71 94 190 68 144 182 100 159 104 8 95 112 151 131 141 65 168 21 146 166 45 96 22 1 156 163 184 35 97 36 79 120 131 21 140 27 3 192 186 59 0 81 171 152 12 113 169 132 86 115 99 83 163 121 37 119 36 21 154 85 57 185 157 140 7 97 167 162 90 154 22 42 35 193 146 0 58 115 84 97 182 183 180 145 57 17 64 45 190 171 83 48 156 40 188 163 138 156 78 180 62 100 22 49 45 169 49 104 36 134 153 171 69 133 116 78 103 133 124 93 104 7 93 12 199 82 128 137 190 6 69 52 106 92 101 151 13 103 7 1 189 160 172 10 46 89 89 101 174 165 194 30 124 40 42 123 74 170 13 64 176 82 68 34 126 169 186 139 24 193 141 13 106 113 24 152 154 65 53 128 182 199 158 106 39 1 181 113 123 194 129 100 29 197 134 155 119 72 95 143 18 188 109 124 101 85 76 8 102 81 136 84 32 47 142 72 0 123 137 123 70 67 175 99 16 110 6 135 134 101 31 152 89 92 76 143 129 104 151 31 185 39 115 170 38 57 42 190 132 131 114 154 150 41 53 167 103 60 54 38 113 37 190 155 81 19 98 10 123 1 41 61 192 108 31 31 117 25 21 50 108 87 4 59 129 10 178 184 22 32 22 135 22 165 42 103 184 92 66 59 93 107 72 86 168 55 69 85 80 42 87 189 130 92 0 11 54 178 195 76 162 170 163 184 135 6 40 119 98 106 130 192 165 3 30 133 58 51 171 91 93 58 32 175 150 32 138 4 162 86 32 124 56 196 61 191 2 53 62 52 111 192 44 76 147 26 162 6 29 133 49 75 191 81 50 94 65 141 50 179 27 83 103 83 31 116 26 185 121 88 37 32 32 34 61 180 12 175 138 42 108 139 117 51 172 119 97 37 12 148 168 39 183 23 74 14 140 100 151 61 140 188 46 125 22 107 57 35 34 147 29 142 86 98 145 58 17 43 47 30 143 15 21 126 38 96 92 130 148 43 144 41 183 190 118 158 49 127 145 83 74 174 177 160 72 74 170 41 117 17 23 60 32 45 138 22 93 182 153 193 177 97 186 161 39 104 119 40 183 64 123 57 38 52 17 62 126 187 103 196 156 79 8 140 76 147 163 169 81 68 114 59 117 101 20 156 157 139 196 141 155 71 150 145 123 168 7 1 107 62 197 16 141 158 156 17 105 119 138 138 187 53 197 56 106 17 12 15 108 160 108 63 31 59 8 106 179 167 60 38 182 9 54 75 167 11 45 24 82 183 163 22 188 160 78 46 178 43 14 38 3 122 54 187 181 14 45 112 182 105 151 116 115 5 191 34 168 36 59 51 172 22 25 112 182 103 111 112 146 125 151 102 199 157 89 133 171 134 45 153 192 196 21 59 154 13 93 74 1 152 125 125 126 150 190 61 6 101 173 104 178 76 6 177 33 95 110 5 182 156 110 174 104 132 185 10 97 78 85 50 183 162 176 109 65 166 170 71 19 96 127 197 124 134 126 110 29 37 67 163 145 129 137 1 61 122 164 110 153 1 161 136 163 89 197 180 7 120 51 26 16 131 175 92 65 101 2 46 90 69 10 187 199 99 141 12 174 57 75 127 58 36 15 21 125 164 2 84 84 5 110 52 136 37 145 153 90 99 0 181 121 10 120 72 61 13 36 35 70 111 114 128 99 81 102 176 46 104 60 130 61 122 135 150 159 32 103 50 83 55 183 4 65 103 28 79 69 65 114 139 128 181 20 28 62 122 4 108 178 17 191 191 139 78 141 99 110 197 149 193 52 132 150 70 187 178 149 56 43 63 148 172 44 168 152 59 42 108 167 172 125 110 163 65 188 105 164 50 54 65 44 106 149 146 176 88 124 125 145 120 141 45 44 137 165 196 196 159 56 116 131 182 178 94 47 167 151 163 169 5 180 165 112 129 111 40 17 36 166 114 108 59 111 152 196 76 100 145 35 156 61 166 90 39 13 89 158 164 4 128 170 184 45 34 65 157 74 35 145 192 149 53 51 13 157 0 41 9 145 29 117 6 195 8 197 160 97 108 125 102 188
Could you please explain this? If this is python/shell issue and how can I overcome it ? I am trying to run a hackerrank test case which is having very large input around 200000. But I am not able to run that testcase in my terminal due to this limitation.
This is indeed a limitation specific to the shell, rather than Python. Just to bring your attention to some things, here is what you can do in the future:
Initial hint - if you paste this and attempt to add characters in a modern shell you see you can't!
paste your input into a file, preferably with one item on a line.
Add a few debug lines
if __name__ == '__main__':
iplist = list(map(int, input().rstrip().split()))
with open('test.dat','w') as fd:
fd.write('\n'.join(str(x) for x in iplist))
print("len of exp: ",len(iplist),iplist[0],iplist[-1])
So now you have a quick reference to the first and last read items in the list, and a file containing the entire read list. Immediately you see the last item is 188 - suspicious.
If you pasted your input into a file in (1) you can easily check line 1187 is indeed 188.
Using the test file above you can count characters in the input actually read using a tool such as wc -c test.dat.
I get 4095, which is suspiciously close to 4096 = 4 KiB (often written as kB)
This is a clear hint for a "system" level limitation, likely your shell, limiting the amount of characters you are allowed to put in a single line. This specific limitation is pretty standard, and you can probably find somewhere the documentation for the limit.
Jack's answer is the way to go here - this is no way to read large input.
You are correct that there is a character limit in shell commands which it looks like you are hitting with that much of data on the command line.
I would refer you to the man page for that but you will not need to know it precisely hopefully ever.
The reason for that is you'll never want to put yourself in this position and to avoid that, all you need to do is save your input to a file, and change your python to open that file and read it line by line. Many examples on SO how to do something like that.
I hope that helps.
According to the Excel documentation: Learn about syntax rules for names:
Valid characters The first character of a name must be a letter, an
underscore character (_), or a backslash (). Remaining characters in
the name can be letters, numbers, periods, and underscore characters.
But what exactly is a letter?
I thought this means only ASCII letters, like: A-Z and a-z
But obviously I am wrong, because also the following work (on my English Excel 2013):
German umlauts: Ö,ö,Ü,ü, etc.
French accents: é, ê, etc.
So how can I check in VBA which characters in a string are valid and which are not?
I ran this tiny bit of code:
Sub WhatsInAName()
Dim i As Long, CH As String, r As Range, msg As String
Dim K As Long
Set r = Range("A1")
On Error Resume Next
K = 1
For i = 1 To 255
CH = Chr(i)
r.Name = CH
If Err.Number = 0 Then
Cells(K, 1) = i
K = K + 1
Else
Err.Number = 0
End If
Next i
On Error GoTo 0
End Sub
which should record the ascii codes for valid name starters. I got this:
65
66
68
69
70
71
72
73
74
75
76
77
78
79
80
81
83
84
85
86
87
88
89
90
92
95
97
98
100
101
102
103
104
105
106
107
108
109
110
111
112
113
115
116
117
118
119
120
121
122
131
133
134
135
137
138
140
142
145
146
147
148
150
151
153
154
156
158
159
161
164
167
168
170
173
175
176
177
178
179
180
181
182
183
184
185
186
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
I have no idea why 67 is missing.
EDIT#5:
Here is a list of the valid characters after the first character:
32
46
48
49
50
51
52
53
54
55
56
57
63
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
92
95
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
128
131
133
134
135
136
137
138
140
142
145
146
147
148
150
151
152
153
154
156
158
159
161
164
167
168
170
173
175
176
177
178
179
180
181
182
183
184
185
186
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
Thanks to Martin Trummer.
It turns out that the answer to the question is quite complex. The answer from user
Gary's Student is already quite close, but here are more things to consider:
single-character names:
Examples:
"a" is allowed
"c" is not allowed
characters at the start:
Examples:
"cX" is allowed
"?X" is not allowed
characters after the start
Examples:
"_?" is allowed ("?", "?_" are not)
combinations:
"R1048576C1" invalid
"R1048577C1" valid
"\xx" valid
"\x" invalid
unicode
Workbook names vs. Worksheet names:
e.g. "\a" is allowed on the Worksheet, but not on the Workbook
I've made a GitHub project excel-names which includes an Excel Sheet with a list of valid characters (also unicode) and some VBA code that you can use.
Moreover, the project includes functions that consider the full Excel Name (not only single characters): read the documentation for full details
I know this is old and I might be a litle off topic but I have just ran into a problem whit Excel named ranges.
I was trying to use names like CP01 , CP02, ... and, well, excel keeps telling that those were invalid names although no invalid characters were in the name.
Adding an underscore solves the problem. Names like CP01_ or CP_01 works just fine.
So there is resctriction with valid characters and, as has already been refered, there are also restrictions with the combination of the characters.
I haven't been throug the bottom of the question but, besides the previousily refered combinations of characters, it's not also possible to use any combination of characters that can be interperted as cell adress in A1 notation.
I want to find line number of file by search word. Two variable, Start line and End line. Start Line must has word "COPY" and End line must has word "\."
When I try type command in stdout.
Find line number of "COPY" word.
-bash-4.1$ cat src_bakfile/merge_cdr_20130901.dat |awk '/COPY/ {print NR;}'
41
285
293
301
309
317
Find line number of "\." word.
-bash-4.1$ cat src_bakfile/merge_cdr_20130901.dat |awk '/\\\./ {print NR;}'
278
286
294
302
310
394
Results OK, correct.
But when I write to shell script and run. Results of find "\." is wrong.
-bash-4.1$ . test_cutbakfile.sh
Start Line ->
41 285 293 301 309 317
End Line ->
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 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 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 286 294 302 310 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394
This is my shell script.
#!/bin/sh
#-- Config --#
main_path="/home/hdmfec/ibank"
src_path="${main_path}/src_bakfile"
for bakfile in `ls ${src_path}`
do
startlines=`cat ${src_path}/${bakfile} |awk '/COPY/ {print NR;}'`
endlines=`cat ${src_path}/${bakfile} |awk '/\\\./ {print NR;}'`
echo "Start Line ->"
echo ${startlines}
echo -e "\n"
echo "End Line ->"
echo ${endlines}
done
Why's stdout and shell script output not same? please advice me.
Because command substitution (using `backquotes`) treats backquotes specially. You will have to quote every \ again. Or use $() command substitution, as suggested elsewhere.
This should work better:
endlines=`cat ${src_path}/${bakfile} |awk '/\\\\\\./ {print NR;}'`
Better just use $(). It's POSIX compatible. And quote your variables properly around "". Also, using cat is not needed.
for bakfile in $(ls "${src_path}")
do
startlines=$(awk '/COPY/ {print NR;}' "${src_path}/${bakfile}")
endlines=$(awk '/\\\./ {print NR;}' "${src_path}/${bakfile}")
You need to use double quotes in your echo statements. Have your script like this:
startlines=$(cat ${src_path}/${bakfile} |awk '/COPY/ {print NR;}')
endlines=$(cat ${src_path}/${bakfile} |awk '/\\\./ {print NR;}')
echo "Start Line ->"
echo "${startlines}"
echo -e "\n"
echo "End Line ->"
echo "${endlines}"
Without double quotes shell prints new lines as space since shell treats all individual strings as a separate argument without quotes.
PS: You should also avoid parsing ls's output and use find instead like this:
while read bakfile; do
startlines=$(cat ${src_path}/${bakfile} |awk '/COPY/ {print NR;}')
endlines=$(cat ${src_path}/${bakfile} |awk '/\\\./ {print NR;}')
echo "Start Line ->"
echo "${startlines}"
echo -e "\n"
echo "End Line ->"
echo "${endlines}"
done < <(find "$src_path" -type f -maxdepth 1)