How To Use grep Command In Linux to filter values in a line?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
5
down vote

favorite
1












I am trying to read the temperature from my Avalon which has the Avalon Firmware: 20170603



I'm using the command:



cgminer-api -o stats



It brings me a lot of information that I don´t need.



root@OpenWrt:/etc# cgminer-api -o stats
STATUS=S,When=1482343577,Code=70,Msg=CGMiner stats,Description=cgminer 4.10.0|STATS=0,ID=AV70,Elapsed=30789,Calls=0,Wait=0.000000,Max=0.000000,Min=99999999.000000,MM ID1=Ver[7411612-6cf14b0] DNA[01313edbc5efabe3] Elapsed[30792] MW[340560 340538 340538 340538] LW[1362174] MH[180 238 259 216] HW[893] DH[2.749%] Temp[30] TMax[77] Fan[5430] FanR[90%] Vi[1201 1201 1202 1202] Vo[4438 4406 4443 4438] GHSmm[8063.47] WU[108083.46] Freq[715.86] PG[15] Led[0] MW0[1170 1302 1206 1250 1197 1312 1331 1262 1300 1216 1230 1281 1265 1273 1327 1291 1232 1231 1267 1292 1286 1203] MW1[1312 1189 1237 1251 1212 1247 1264 1275 1196 1256 1283 1257 1190 1247 1243 1282 1330 1315 1292 1273 1261 1271] MW2[1213 1262 1310 1202 1285 1220 1291 1267 1309 1307 1164 1212 1290 1289 1308 1174 1230 1276 1252 1189 1192 1242] MW3[1302 1275 1209 1307 1217 1294 1328 1273 1237 1256 1227 1239 1268 1242 1308 1314 1296 1314 1331 1324 1297 1190] TA[88] ECHU[512 0 0 0] ECMM[0] FM[1] CRC[974 0 0 0] PAIRS[0 0 0] PVT_T[4-70/0-76/72 0-69/11-76/70 2-70/0-77/74 20-67/0-75/70],MM ID2=Ver[7411612-6cf14b0] DNA[0132c3d0691693b9] Elapsed[30791] MW[340551 340551 340538 340538] LW[1362178] MH[2067 188 222 215] HW[2692] DH[3.629%] Temp[29] TMax[80] Fan[5490] FanR[90%] Vi[1204 1202 1201 1201] Vo[4461 4447 4420 4443] GHSmm[7887.76] WU[103670.36] Freq[700.26] PG[15] Led[0] MW0[1264 1270 1229 1313 1296 1184 1239 1237 1266 1247 1252 1242 1202 1266 1266 1317 1255 1272 1309 1230 1301 1243] MW1[1155 1159 1213 1196 1214 1154 1152 1213 1180 1180 1152 1193 1118 1122 1159 1173 1185 1193 1180 1161 1170 1175] MW2[1269 1138 1285 1180 1256 1210 1170 1299 1223 1185 1164 1132 1140 1225 1246 1173 1237 1212 1192 1284 1215 1205] MW3[762 1268 1187 1271 1277 1150 1202 1208 1172 1170 1176 1249 1177 1154 1197 1250 1176 1227 1268 1218 1262 1251] TA[88] ECHU[0 512 0 0] ECMM[0] FM[1] CRC[0 0 0 0] PAIRS[0 0 0] PVT_T[0-68/10-80/70 19-67/0-76/70 0-70/11-78/72 19-68/0-77/71],MM Count=2,Smart Speed=1,Connecter=AUC,AUC VER=AUC-20151208,AUC I2C Speed=400000,AUC I2C XDelay=19200,AUC Sensor=15483,AUC Temperature=28.17,Connection Overloaded=false,Voltage Offset=0,Nonce Mask=29,USB Pipe=0,USB Delay=r0 0.000000 w0 0.000000,USB tmo=0 0|STATS=1,ID=POOL0,Elapsed=30789,Calls=0,Wait=0.000000,Max=0.000000,Min=99999999.000000,Pool Calls=0,Pool Attempts=0,Pool Wait=0.000000,Pool Max=0.000000,Pool Min=99999999.000000,Pool Av=0.000000,Work Had Roll Time=false,Work Can Roll=false,Work Had Expire=false,Work Roll Time=0,Work Diff=65536.00000000,Min Diff=1.00000000,Max Diff=131072.00000000,Min Diff Count=12,Max Diff Count=18313,Times Sent=1531,Bytes Sent=228345,Times Recv=2668,Bytes Recv=1379612,Net Bytes Sent=228345,Net Bytes Recv=1379612|STATS=2,ID=POOL1,Elapsed=30789,Calls=0,Wait=0.000000,Max=0.000000,Min=99999999.000000,Pool Calls=0,Pool Attempts=0,Pool Wait=0.000000,Pool Max=0.000000,Pool Min=99999999.000000,Pool Av=0.000000,Work Had Roll Time=false,Work Can Roll=false,Work Had Expire=false,Work Roll Time=0,Work Diff=16384.00000000,Min Diff=4096.00000000,Max Diff=16384.00000000,Min Diff Count=374,Max Diff Count=993,Times Sent=109,Bytes Sent=12038,Times Recv=119,Bytes Recv=12214,Net Bytes Sent=12038,Net Bytes Recv=12214|STATS=3,ID=POOL2,Elapsed=30789,Calls=0,Wait=0.000000,Max=0.000000,Min=99999999.000000,Pool Calls=0,Pool Attempts=0,Pool Wait=0.000000,Pool Max=0.000000,Pool Min=99999999.000000,Pool Av=0.000000,Work Had Roll Time=false,Work Can Roll=false,Work Had Expire=false,Work Roll Time=0,Work Diff=0.00000000,Min Diff=0.00000000,Max Diff=0.00000000,Min Diff Count=0,Max Diff Count=0,Times Sent=2,Bytes Sent=151,Times Recv=3,Bytes Recv=244,Net Bytes Sent=151,Net Bytes Recv=244|


But I just need this values:



 Temp[29] TMax[80] Fan[5490]
Temp[29] TMax[80] Fan[5490]


I tried with this two commands but they didn´t work



1.- cgminer-api stats | grep "^ *[temp_avg]"
2.- cgminer-api stats | grep temp






share|improve this question






















  • Why does the question specify "grep" when you don't really care which tool is used (and, f/e, are willing to accept an answer that uses awk)? Not so much the case with OpenWRT where you only have busybox ash as an available shell, but in many questions of this nature the best approach uses only native bash builtin functionality (ie. [[ $string =~ $regex ]] matching to populate BASH_REMATCH).
    – Charles Duffy
    Jan 13 at 17:23















up vote
5
down vote

favorite
1












I am trying to read the temperature from my Avalon which has the Avalon Firmware: 20170603



I'm using the command:



cgminer-api -o stats



It brings me a lot of information that I don´t need.



root@OpenWrt:/etc# cgminer-api -o stats
STATUS=S,When=1482343577,Code=70,Msg=CGMiner stats,Description=cgminer 4.10.0|STATS=0,ID=AV70,Elapsed=30789,Calls=0,Wait=0.000000,Max=0.000000,Min=99999999.000000,MM ID1=Ver[7411612-6cf14b0] DNA[01313edbc5efabe3] Elapsed[30792] MW[340560 340538 340538 340538] LW[1362174] MH[180 238 259 216] HW[893] DH[2.749%] Temp[30] TMax[77] Fan[5430] FanR[90%] Vi[1201 1201 1202 1202] Vo[4438 4406 4443 4438] GHSmm[8063.47] WU[108083.46] Freq[715.86] PG[15] Led[0] MW0[1170 1302 1206 1250 1197 1312 1331 1262 1300 1216 1230 1281 1265 1273 1327 1291 1232 1231 1267 1292 1286 1203] MW1[1312 1189 1237 1251 1212 1247 1264 1275 1196 1256 1283 1257 1190 1247 1243 1282 1330 1315 1292 1273 1261 1271] MW2[1213 1262 1310 1202 1285 1220 1291 1267 1309 1307 1164 1212 1290 1289 1308 1174 1230 1276 1252 1189 1192 1242] MW3[1302 1275 1209 1307 1217 1294 1328 1273 1237 1256 1227 1239 1268 1242 1308 1314 1296 1314 1331 1324 1297 1190] TA[88] ECHU[512 0 0 0] ECMM[0] FM[1] CRC[974 0 0 0] PAIRS[0 0 0] PVT_T[4-70/0-76/72 0-69/11-76/70 2-70/0-77/74 20-67/0-75/70],MM ID2=Ver[7411612-6cf14b0] DNA[0132c3d0691693b9] Elapsed[30791] MW[340551 340551 340538 340538] LW[1362178] MH[2067 188 222 215] HW[2692] DH[3.629%] Temp[29] TMax[80] Fan[5490] FanR[90%] Vi[1204 1202 1201 1201] Vo[4461 4447 4420 4443] GHSmm[7887.76] WU[103670.36] Freq[700.26] PG[15] Led[0] MW0[1264 1270 1229 1313 1296 1184 1239 1237 1266 1247 1252 1242 1202 1266 1266 1317 1255 1272 1309 1230 1301 1243] MW1[1155 1159 1213 1196 1214 1154 1152 1213 1180 1180 1152 1193 1118 1122 1159 1173 1185 1193 1180 1161 1170 1175] MW2[1269 1138 1285 1180 1256 1210 1170 1299 1223 1185 1164 1132 1140 1225 1246 1173 1237 1212 1192 1284 1215 1205] MW3[762 1268 1187 1271 1277 1150 1202 1208 1172 1170 1176 1249 1177 1154 1197 1250 1176 1227 1268 1218 1262 1251] TA[88] ECHU[0 512 0 0] ECMM[0] FM[1] CRC[0 0 0 0] PAIRS[0 0 0] PVT_T[0-68/10-80/70 19-67/0-76/70 0-70/11-78/72 19-68/0-77/71],MM Count=2,Smart Speed=1,Connecter=AUC,AUC VER=AUC-20151208,AUC I2C Speed=400000,AUC I2C XDelay=19200,AUC Sensor=15483,AUC Temperature=28.17,Connection Overloaded=false,Voltage Offset=0,Nonce Mask=29,USB Pipe=0,USB Delay=r0 0.000000 w0 0.000000,USB tmo=0 0|STATS=1,ID=POOL0,Elapsed=30789,Calls=0,Wait=0.000000,Max=0.000000,Min=99999999.000000,Pool Calls=0,Pool Attempts=0,Pool Wait=0.000000,Pool Max=0.000000,Pool Min=99999999.000000,Pool Av=0.000000,Work Had Roll Time=false,Work Can Roll=false,Work Had Expire=false,Work Roll Time=0,Work Diff=65536.00000000,Min Diff=1.00000000,Max Diff=131072.00000000,Min Diff Count=12,Max Diff Count=18313,Times Sent=1531,Bytes Sent=228345,Times Recv=2668,Bytes Recv=1379612,Net Bytes Sent=228345,Net Bytes Recv=1379612|STATS=2,ID=POOL1,Elapsed=30789,Calls=0,Wait=0.000000,Max=0.000000,Min=99999999.000000,Pool Calls=0,Pool Attempts=0,Pool Wait=0.000000,Pool Max=0.000000,Pool Min=99999999.000000,Pool Av=0.000000,Work Had Roll Time=false,Work Can Roll=false,Work Had Expire=false,Work Roll Time=0,Work Diff=16384.00000000,Min Diff=4096.00000000,Max Diff=16384.00000000,Min Diff Count=374,Max Diff Count=993,Times Sent=109,Bytes Sent=12038,Times Recv=119,Bytes Recv=12214,Net Bytes Sent=12038,Net Bytes Recv=12214|STATS=3,ID=POOL2,Elapsed=30789,Calls=0,Wait=0.000000,Max=0.000000,Min=99999999.000000,Pool Calls=0,Pool Attempts=0,Pool Wait=0.000000,Pool Max=0.000000,Pool Min=99999999.000000,Pool Av=0.000000,Work Had Roll Time=false,Work Can Roll=false,Work Had Expire=false,Work Roll Time=0,Work Diff=0.00000000,Min Diff=0.00000000,Max Diff=0.00000000,Min Diff Count=0,Max Diff Count=0,Times Sent=2,Bytes Sent=151,Times Recv=3,Bytes Recv=244,Net Bytes Sent=151,Net Bytes Recv=244|


But I just need this values:



 Temp[29] TMax[80] Fan[5490]
Temp[29] TMax[80] Fan[5490]


I tried with this two commands but they didn´t work



1.- cgminer-api stats | grep "^ *[temp_avg]"
2.- cgminer-api stats | grep temp






share|improve this question






















  • Why does the question specify "grep" when you don't really care which tool is used (and, f/e, are willing to accept an answer that uses awk)? Not so much the case with OpenWRT where you only have busybox ash as an available shell, but in many questions of this nature the best approach uses only native bash builtin functionality (ie. [[ $string =~ $regex ]] matching to populate BASH_REMATCH).
    – Charles Duffy
    Jan 13 at 17:23













up vote
5
down vote

favorite
1









up vote
5
down vote

favorite
1






1





I am trying to read the temperature from my Avalon which has the Avalon Firmware: 20170603



I'm using the command:



cgminer-api -o stats



It brings me a lot of information that I don´t need.



root@OpenWrt:/etc# cgminer-api -o stats
STATUS=S,When=1482343577,Code=70,Msg=CGMiner stats,Description=cgminer 4.10.0|STATS=0,ID=AV70,Elapsed=30789,Calls=0,Wait=0.000000,Max=0.000000,Min=99999999.000000,MM ID1=Ver[7411612-6cf14b0] DNA[01313edbc5efabe3] Elapsed[30792] MW[340560 340538 340538 340538] LW[1362174] MH[180 238 259 216] HW[893] DH[2.749%] Temp[30] TMax[77] Fan[5430] FanR[90%] Vi[1201 1201 1202 1202] Vo[4438 4406 4443 4438] GHSmm[8063.47] WU[108083.46] Freq[715.86] PG[15] Led[0] MW0[1170 1302 1206 1250 1197 1312 1331 1262 1300 1216 1230 1281 1265 1273 1327 1291 1232 1231 1267 1292 1286 1203] MW1[1312 1189 1237 1251 1212 1247 1264 1275 1196 1256 1283 1257 1190 1247 1243 1282 1330 1315 1292 1273 1261 1271] MW2[1213 1262 1310 1202 1285 1220 1291 1267 1309 1307 1164 1212 1290 1289 1308 1174 1230 1276 1252 1189 1192 1242] MW3[1302 1275 1209 1307 1217 1294 1328 1273 1237 1256 1227 1239 1268 1242 1308 1314 1296 1314 1331 1324 1297 1190] TA[88] ECHU[512 0 0 0] ECMM[0] FM[1] CRC[974 0 0 0] PAIRS[0 0 0] PVT_T[4-70/0-76/72 0-69/11-76/70 2-70/0-77/74 20-67/0-75/70],MM ID2=Ver[7411612-6cf14b0] DNA[0132c3d0691693b9] Elapsed[30791] MW[340551 340551 340538 340538] LW[1362178] MH[2067 188 222 215] HW[2692] DH[3.629%] Temp[29] TMax[80] Fan[5490] FanR[90%] Vi[1204 1202 1201 1201] Vo[4461 4447 4420 4443] GHSmm[7887.76] WU[103670.36] Freq[700.26] PG[15] Led[0] MW0[1264 1270 1229 1313 1296 1184 1239 1237 1266 1247 1252 1242 1202 1266 1266 1317 1255 1272 1309 1230 1301 1243] MW1[1155 1159 1213 1196 1214 1154 1152 1213 1180 1180 1152 1193 1118 1122 1159 1173 1185 1193 1180 1161 1170 1175] MW2[1269 1138 1285 1180 1256 1210 1170 1299 1223 1185 1164 1132 1140 1225 1246 1173 1237 1212 1192 1284 1215 1205] MW3[762 1268 1187 1271 1277 1150 1202 1208 1172 1170 1176 1249 1177 1154 1197 1250 1176 1227 1268 1218 1262 1251] TA[88] ECHU[0 512 0 0] ECMM[0] FM[1] CRC[0 0 0 0] PAIRS[0 0 0] PVT_T[0-68/10-80/70 19-67/0-76/70 0-70/11-78/72 19-68/0-77/71],MM Count=2,Smart Speed=1,Connecter=AUC,AUC VER=AUC-20151208,AUC I2C Speed=400000,AUC I2C XDelay=19200,AUC Sensor=15483,AUC Temperature=28.17,Connection Overloaded=false,Voltage Offset=0,Nonce Mask=29,USB Pipe=0,USB Delay=r0 0.000000 w0 0.000000,USB tmo=0 0|STATS=1,ID=POOL0,Elapsed=30789,Calls=0,Wait=0.000000,Max=0.000000,Min=99999999.000000,Pool Calls=0,Pool Attempts=0,Pool Wait=0.000000,Pool Max=0.000000,Pool Min=99999999.000000,Pool Av=0.000000,Work Had Roll Time=false,Work Can Roll=false,Work Had Expire=false,Work Roll Time=0,Work Diff=65536.00000000,Min Diff=1.00000000,Max Diff=131072.00000000,Min Diff Count=12,Max Diff Count=18313,Times Sent=1531,Bytes Sent=228345,Times Recv=2668,Bytes Recv=1379612,Net Bytes Sent=228345,Net Bytes Recv=1379612|STATS=2,ID=POOL1,Elapsed=30789,Calls=0,Wait=0.000000,Max=0.000000,Min=99999999.000000,Pool Calls=0,Pool Attempts=0,Pool Wait=0.000000,Pool Max=0.000000,Pool Min=99999999.000000,Pool Av=0.000000,Work Had Roll Time=false,Work Can Roll=false,Work Had Expire=false,Work Roll Time=0,Work Diff=16384.00000000,Min Diff=4096.00000000,Max Diff=16384.00000000,Min Diff Count=374,Max Diff Count=993,Times Sent=109,Bytes Sent=12038,Times Recv=119,Bytes Recv=12214,Net Bytes Sent=12038,Net Bytes Recv=12214|STATS=3,ID=POOL2,Elapsed=30789,Calls=0,Wait=0.000000,Max=0.000000,Min=99999999.000000,Pool Calls=0,Pool Attempts=0,Pool Wait=0.000000,Pool Max=0.000000,Pool Min=99999999.000000,Pool Av=0.000000,Work Had Roll Time=false,Work Can Roll=false,Work Had Expire=false,Work Roll Time=0,Work Diff=0.00000000,Min Diff=0.00000000,Max Diff=0.00000000,Min Diff Count=0,Max Diff Count=0,Times Sent=2,Bytes Sent=151,Times Recv=3,Bytes Recv=244,Net Bytes Sent=151,Net Bytes Recv=244|


But I just need this values:



 Temp[29] TMax[80] Fan[5490]
Temp[29] TMax[80] Fan[5490]


I tried with this two commands but they didn´t work



1.- cgminer-api stats | grep "^ *[temp_avg]"
2.- cgminer-api stats | grep temp






share|improve this question














I am trying to read the temperature from my Avalon which has the Avalon Firmware: 20170603



I'm using the command:



cgminer-api -o stats



It brings me a lot of information that I don´t need.



root@OpenWrt:/etc# cgminer-api -o stats
STATUS=S,When=1482343577,Code=70,Msg=CGMiner stats,Description=cgminer 4.10.0|STATS=0,ID=AV70,Elapsed=30789,Calls=0,Wait=0.000000,Max=0.000000,Min=99999999.000000,MM ID1=Ver[7411612-6cf14b0] DNA[01313edbc5efabe3] Elapsed[30792] MW[340560 340538 340538 340538] LW[1362174] MH[180 238 259 216] HW[893] DH[2.749%] Temp[30] TMax[77] Fan[5430] FanR[90%] Vi[1201 1201 1202 1202] Vo[4438 4406 4443 4438] GHSmm[8063.47] WU[108083.46] Freq[715.86] PG[15] Led[0] MW0[1170 1302 1206 1250 1197 1312 1331 1262 1300 1216 1230 1281 1265 1273 1327 1291 1232 1231 1267 1292 1286 1203] MW1[1312 1189 1237 1251 1212 1247 1264 1275 1196 1256 1283 1257 1190 1247 1243 1282 1330 1315 1292 1273 1261 1271] MW2[1213 1262 1310 1202 1285 1220 1291 1267 1309 1307 1164 1212 1290 1289 1308 1174 1230 1276 1252 1189 1192 1242] MW3[1302 1275 1209 1307 1217 1294 1328 1273 1237 1256 1227 1239 1268 1242 1308 1314 1296 1314 1331 1324 1297 1190] TA[88] ECHU[512 0 0 0] ECMM[0] FM[1] CRC[974 0 0 0] PAIRS[0 0 0] PVT_T[4-70/0-76/72 0-69/11-76/70 2-70/0-77/74 20-67/0-75/70],MM ID2=Ver[7411612-6cf14b0] DNA[0132c3d0691693b9] Elapsed[30791] MW[340551 340551 340538 340538] LW[1362178] MH[2067 188 222 215] HW[2692] DH[3.629%] Temp[29] TMax[80] Fan[5490] FanR[90%] Vi[1204 1202 1201 1201] Vo[4461 4447 4420 4443] GHSmm[7887.76] WU[103670.36] Freq[700.26] PG[15] Led[0] MW0[1264 1270 1229 1313 1296 1184 1239 1237 1266 1247 1252 1242 1202 1266 1266 1317 1255 1272 1309 1230 1301 1243] MW1[1155 1159 1213 1196 1214 1154 1152 1213 1180 1180 1152 1193 1118 1122 1159 1173 1185 1193 1180 1161 1170 1175] MW2[1269 1138 1285 1180 1256 1210 1170 1299 1223 1185 1164 1132 1140 1225 1246 1173 1237 1212 1192 1284 1215 1205] MW3[762 1268 1187 1271 1277 1150 1202 1208 1172 1170 1176 1249 1177 1154 1197 1250 1176 1227 1268 1218 1262 1251] TA[88] ECHU[0 512 0 0] ECMM[0] FM[1] CRC[0 0 0 0] PAIRS[0 0 0] PVT_T[0-68/10-80/70 19-67/0-76/70 0-70/11-78/72 19-68/0-77/71],MM Count=2,Smart Speed=1,Connecter=AUC,AUC VER=AUC-20151208,AUC I2C Speed=400000,AUC I2C XDelay=19200,AUC Sensor=15483,AUC Temperature=28.17,Connection Overloaded=false,Voltage Offset=0,Nonce Mask=29,USB Pipe=0,USB Delay=r0 0.000000 w0 0.000000,USB tmo=0 0|STATS=1,ID=POOL0,Elapsed=30789,Calls=0,Wait=0.000000,Max=0.000000,Min=99999999.000000,Pool Calls=0,Pool Attempts=0,Pool Wait=0.000000,Pool Max=0.000000,Pool Min=99999999.000000,Pool Av=0.000000,Work Had Roll Time=false,Work Can Roll=false,Work Had Expire=false,Work Roll Time=0,Work Diff=65536.00000000,Min Diff=1.00000000,Max Diff=131072.00000000,Min Diff Count=12,Max Diff Count=18313,Times Sent=1531,Bytes Sent=228345,Times Recv=2668,Bytes Recv=1379612,Net Bytes Sent=228345,Net Bytes Recv=1379612|STATS=2,ID=POOL1,Elapsed=30789,Calls=0,Wait=0.000000,Max=0.000000,Min=99999999.000000,Pool Calls=0,Pool Attempts=0,Pool Wait=0.000000,Pool Max=0.000000,Pool Min=99999999.000000,Pool Av=0.000000,Work Had Roll Time=false,Work Can Roll=false,Work Had Expire=false,Work Roll Time=0,Work Diff=16384.00000000,Min Diff=4096.00000000,Max Diff=16384.00000000,Min Diff Count=374,Max Diff Count=993,Times Sent=109,Bytes Sent=12038,Times Recv=119,Bytes Recv=12214,Net Bytes Sent=12038,Net Bytes Recv=12214|STATS=3,ID=POOL2,Elapsed=30789,Calls=0,Wait=0.000000,Max=0.000000,Min=99999999.000000,Pool Calls=0,Pool Attempts=0,Pool Wait=0.000000,Pool Max=0.000000,Pool Min=99999999.000000,Pool Av=0.000000,Work Had Roll Time=false,Work Can Roll=false,Work Had Expire=false,Work Roll Time=0,Work Diff=0.00000000,Min Diff=0.00000000,Max Diff=0.00000000,Min Diff Count=0,Max Diff Count=0,Times Sent=2,Bytes Sent=151,Times Recv=3,Bytes Recv=244,Net Bytes Sent=151,Net Bytes Recv=244|


But I just need this values:



 Temp[29] TMax[80] Fan[5490]
Temp[29] TMax[80] Fan[5490]


I tried with this two commands but they didn´t work



1.- cgminer-api stats | grep "^ *[temp_avg]"
2.- cgminer-api stats | grep temp








share|improve this question













share|improve this question




share|improve this question








edited Jan 12 at 22:51









DopeGhoti

40.5k54979




40.5k54979










asked Jan 12 at 22:34









mavi

284




284











  • Why does the question specify "grep" when you don't really care which tool is used (and, f/e, are willing to accept an answer that uses awk)? Not so much the case with OpenWRT where you only have busybox ash as an available shell, but in many questions of this nature the best approach uses only native bash builtin functionality (ie. [[ $string =~ $regex ]] matching to populate BASH_REMATCH).
    – Charles Duffy
    Jan 13 at 17:23

















  • Why does the question specify "grep" when you don't really care which tool is used (and, f/e, are willing to accept an answer that uses awk)? Not so much the case with OpenWRT where you only have busybox ash as an available shell, but in many questions of this nature the best approach uses only native bash builtin functionality (ie. [[ $string =~ $regex ]] matching to populate BASH_REMATCH).
    – Charles Duffy
    Jan 13 at 17:23
















Why does the question specify "grep" when you don't really care which tool is used (and, f/e, are willing to accept an answer that uses awk)? Not so much the case with OpenWRT where you only have busybox ash as an available shell, but in many questions of this nature the best approach uses only native bash builtin functionality (ie. [[ $string =~ $regex ]] matching to populate BASH_REMATCH).
– Charles Duffy
Jan 13 at 17:23





Why does the question specify "grep" when you don't really care which tool is used (and, f/e, are willing to accept an answer that uses awk)? Not so much the case with OpenWRT where you only have busybox ash as an available shell, but in many questions of this nature the best approach uses only native bash builtin functionality (ie. [[ $string =~ $regex ]] matching to populate BASH_REMATCH).
– Charles Duffy
Jan 13 at 17:23











4 Answers
4






active

oldest

votes

















up vote
7
down vote



accepted










Try:



$ grep -oE 'Temp[^F]*Fan[[[:digit:]]+]' text
Temp[30] TMax[77] Fan[5430]
Temp[29] TMax[80] Fan[5490]


How it works



  • -o tells grep to print only the matching text and not the rest of the line.


  • -E tells grep to use extended regular expressions. (The default basic regular expressions are archaic.)



  • Temp[^F]*Fan[[[:digit:]]+]



    This regex matches any string that starts with Temp, followed by any number of characters that don't include F, followed by Fan followed by a literal [, followed by one or more digits, followed by a literal ].







share|improve this answer






















  • Your output does not match the requested output -- specifically, the percentage value not mentioned as desired output.
    – DopeGhoti
    Jan 12 at 22:49







  • 1




    @DopeGhoti Thanks. You are right. I must be going blind.
    – John1024
    Jan 12 at 22:53






  • 1




    Thanks. It is true that the desired output is not in the answer but I think I can figure out how it is done. Although it would be great that you edit your answer. Thanks bought
    – mavi
    Jan 12 at 22:54






  • 1




    @mavi I updated it with your desired output.
    – John1024
    Jan 12 at 22:54

















up vote
12
down vote













Looks like the requested fields are the eighteenth, nineteenth, and twentieth fields as separated by whitespace, so:



$ awk ' print $18, $19, $20 ' /path/to/input
Temp[30] TMax[77] Fan[5430]





share|improve this answer




















  • This is a great answer too. Thanks!
    – mavi
    Jan 12 at 23:22

















up vote
3
down vote













This works:



grep -o 'Temp[[^]]+] TMax[[^]]+] Fan[[^]]+]'


Search the input string for:
Temp[ Start with Temp and a literal [
[^]]+ Not a closing], several times +.
TMax[[^]]+] Fan[[^]]+] repeat with TMax and Fan.

And print only it: -o.






share|improve this answer





























    up vote
    2
    down vote













    General purpose commandline tools like awk, grep and perl are commonly used for this kind of problems. The cut command is a minimalistic, purpose built tool for it:



    cut -d -f 18,19,20






    share|improve this answer




















      Your Answer







      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "106"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      convertImagesToLinks: false,
      noModals: false,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );








       

      draft saved


      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f416693%2fhow-to-use-grep-command-in-linux-to-filter-values-in-a-line%23new-answer', 'question_page');

      );

      Post as a guest






























      4 Answers
      4






      active

      oldest

      votes








      4 Answers
      4






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      7
      down vote



      accepted










      Try:



      $ grep -oE 'Temp[^F]*Fan[[[:digit:]]+]' text
      Temp[30] TMax[77] Fan[5430]
      Temp[29] TMax[80] Fan[5490]


      How it works



      • -o tells grep to print only the matching text and not the rest of the line.


      • -E tells grep to use extended regular expressions. (The default basic regular expressions are archaic.)



      • Temp[^F]*Fan[[[:digit:]]+]



        This regex matches any string that starts with Temp, followed by any number of characters that don't include F, followed by Fan followed by a literal [, followed by one or more digits, followed by a literal ].







      share|improve this answer






















      • Your output does not match the requested output -- specifically, the percentage value not mentioned as desired output.
        – DopeGhoti
        Jan 12 at 22:49







      • 1




        @DopeGhoti Thanks. You are right. I must be going blind.
        – John1024
        Jan 12 at 22:53






      • 1




        Thanks. It is true that the desired output is not in the answer but I think I can figure out how it is done. Although it would be great that you edit your answer. Thanks bought
        – mavi
        Jan 12 at 22:54






      • 1




        @mavi I updated it with your desired output.
        – John1024
        Jan 12 at 22:54














      up vote
      7
      down vote



      accepted










      Try:



      $ grep -oE 'Temp[^F]*Fan[[[:digit:]]+]' text
      Temp[30] TMax[77] Fan[5430]
      Temp[29] TMax[80] Fan[5490]


      How it works



      • -o tells grep to print only the matching text and not the rest of the line.


      • -E tells grep to use extended regular expressions. (The default basic regular expressions are archaic.)



      • Temp[^F]*Fan[[[:digit:]]+]



        This regex matches any string that starts with Temp, followed by any number of characters that don't include F, followed by Fan followed by a literal [, followed by one or more digits, followed by a literal ].







      share|improve this answer






















      • Your output does not match the requested output -- specifically, the percentage value not mentioned as desired output.
        – DopeGhoti
        Jan 12 at 22:49







      • 1




        @DopeGhoti Thanks. You are right. I must be going blind.
        – John1024
        Jan 12 at 22:53






      • 1




        Thanks. It is true that the desired output is not in the answer but I think I can figure out how it is done. Although it would be great that you edit your answer. Thanks bought
        – mavi
        Jan 12 at 22:54






      • 1




        @mavi I updated it with your desired output.
        – John1024
        Jan 12 at 22:54












      up vote
      7
      down vote



      accepted







      up vote
      7
      down vote



      accepted






      Try:



      $ grep -oE 'Temp[^F]*Fan[[[:digit:]]+]' text
      Temp[30] TMax[77] Fan[5430]
      Temp[29] TMax[80] Fan[5490]


      How it works



      • -o tells grep to print only the matching text and not the rest of the line.


      • -E tells grep to use extended regular expressions. (The default basic regular expressions are archaic.)



      • Temp[^F]*Fan[[[:digit:]]+]



        This regex matches any string that starts with Temp, followed by any number of characters that don't include F, followed by Fan followed by a literal [, followed by one or more digits, followed by a literal ].







      share|improve this answer














      Try:



      $ grep -oE 'Temp[^F]*Fan[[[:digit:]]+]' text
      Temp[30] TMax[77] Fan[5430]
      Temp[29] TMax[80] Fan[5490]


      How it works



      • -o tells grep to print only the matching text and not the rest of the line.


      • -E tells grep to use extended regular expressions. (The default basic regular expressions are archaic.)



      • Temp[^F]*Fan[[[:digit:]]+]



        This regex matches any string that starts with Temp, followed by any number of characters that don't include F, followed by Fan followed by a literal [, followed by one or more digits, followed by a literal ].








      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Jan 12 at 22:57

























      answered Jan 12 at 22:41









      John1024

      44.2k4100116




      44.2k4100116











      • Your output does not match the requested output -- specifically, the percentage value not mentioned as desired output.
        – DopeGhoti
        Jan 12 at 22:49







      • 1




        @DopeGhoti Thanks. You are right. I must be going blind.
        – John1024
        Jan 12 at 22:53






      • 1




        Thanks. It is true that the desired output is not in the answer but I think I can figure out how it is done. Although it would be great that you edit your answer. Thanks bought
        – mavi
        Jan 12 at 22:54






      • 1




        @mavi I updated it with your desired output.
        – John1024
        Jan 12 at 22:54
















      • Your output does not match the requested output -- specifically, the percentage value not mentioned as desired output.
        – DopeGhoti
        Jan 12 at 22:49







      • 1




        @DopeGhoti Thanks. You are right. I must be going blind.
        – John1024
        Jan 12 at 22:53






      • 1




        Thanks. It is true that the desired output is not in the answer but I think I can figure out how it is done. Although it would be great that you edit your answer. Thanks bought
        – mavi
        Jan 12 at 22:54






      • 1




        @mavi I updated it with your desired output.
        – John1024
        Jan 12 at 22:54















      Your output does not match the requested output -- specifically, the percentage value not mentioned as desired output.
      – DopeGhoti
      Jan 12 at 22:49





      Your output does not match the requested output -- specifically, the percentage value not mentioned as desired output.
      – DopeGhoti
      Jan 12 at 22:49





      1




      1




      @DopeGhoti Thanks. You are right. I must be going blind.
      – John1024
      Jan 12 at 22:53




      @DopeGhoti Thanks. You are right. I must be going blind.
      – John1024
      Jan 12 at 22:53




      1




      1




      Thanks. It is true that the desired output is not in the answer but I think I can figure out how it is done. Although it would be great that you edit your answer. Thanks bought
      – mavi
      Jan 12 at 22:54




      Thanks. It is true that the desired output is not in the answer but I think I can figure out how it is done. Although it would be great that you edit your answer. Thanks bought
      – mavi
      Jan 12 at 22:54




      1




      1




      @mavi I updated it with your desired output.
      – John1024
      Jan 12 at 22:54




      @mavi I updated it with your desired output.
      – John1024
      Jan 12 at 22:54












      up vote
      12
      down vote













      Looks like the requested fields are the eighteenth, nineteenth, and twentieth fields as separated by whitespace, so:



      $ awk ' print $18, $19, $20 ' /path/to/input
      Temp[30] TMax[77] Fan[5430]





      share|improve this answer




















      • This is a great answer too. Thanks!
        – mavi
        Jan 12 at 23:22














      up vote
      12
      down vote













      Looks like the requested fields are the eighteenth, nineteenth, and twentieth fields as separated by whitespace, so:



      $ awk ' print $18, $19, $20 ' /path/to/input
      Temp[30] TMax[77] Fan[5430]





      share|improve this answer




















      • This is a great answer too. Thanks!
        – mavi
        Jan 12 at 23:22












      up vote
      12
      down vote










      up vote
      12
      down vote









      Looks like the requested fields are the eighteenth, nineteenth, and twentieth fields as separated by whitespace, so:



      $ awk ' print $18, $19, $20 ' /path/to/input
      Temp[30] TMax[77] Fan[5430]





      share|improve this answer












      Looks like the requested fields are the eighteenth, nineteenth, and twentieth fields as separated by whitespace, so:



      $ awk ' print $18, $19, $20 ' /path/to/input
      Temp[30] TMax[77] Fan[5430]






      share|improve this answer












      share|improve this answer



      share|improve this answer










      answered Jan 12 at 22:48









      DopeGhoti

      40.5k54979




      40.5k54979











      • This is a great answer too. Thanks!
        – mavi
        Jan 12 at 23:22
















      • This is a great answer too. Thanks!
        – mavi
        Jan 12 at 23:22















      This is a great answer too. Thanks!
      – mavi
      Jan 12 at 23:22




      This is a great answer too. Thanks!
      – mavi
      Jan 12 at 23:22










      up vote
      3
      down vote













      This works:



      grep -o 'Temp[[^]]+] TMax[[^]]+] Fan[[^]]+]'


      Search the input string for:
      Temp[ Start with Temp and a literal [
      [^]]+ Not a closing], several times +.
      TMax[[^]]+] Fan[[^]]+] repeat with TMax and Fan.

      And print only it: -o.






      share|improve this answer


























        up vote
        3
        down vote













        This works:



        grep -o 'Temp[[^]]+] TMax[[^]]+] Fan[[^]]+]'


        Search the input string for:
        Temp[ Start with Temp and a literal [
        [^]]+ Not a closing], several times +.
        TMax[[^]]+] Fan[[^]]+] repeat with TMax and Fan.

        And print only it: -o.






        share|improve this answer
























          up vote
          3
          down vote










          up vote
          3
          down vote









          This works:



          grep -o 'Temp[[^]]+] TMax[[^]]+] Fan[[^]]+]'


          Search the input string for:
          Temp[ Start with Temp and a literal [
          [^]]+ Not a closing], several times +.
          TMax[[^]]+] Fan[[^]]+] repeat with TMax and Fan.

          And print only it: -o.






          share|improve this answer














          This works:



          grep -o 'Temp[[^]]+] TMax[[^]]+] Fan[[^]]+]'


          Search the input string for:
          Temp[ Start with Temp and a literal [
          [^]]+ Not a closing], several times +.
          TMax[[^]]+] Fan[[^]]+] repeat with TMax and Fan.

          And print only it: -o.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Jan 12 at 23:01

























          answered Jan 12 at 22:54









          Isaac

          6,7811834




          6,7811834




















              up vote
              2
              down vote













              General purpose commandline tools like awk, grep and perl are commonly used for this kind of problems. The cut command is a minimalistic, purpose built tool for it:



              cut -d -f 18,19,20






              share|improve this answer
























                up vote
                2
                down vote













                General purpose commandline tools like awk, grep and perl are commonly used for this kind of problems. The cut command is a minimalistic, purpose built tool for it:



                cut -d -f 18,19,20






                share|improve this answer






















                  up vote
                  2
                  down vote










                  up vote
                  2
                  down vote









                  General purpose commandline tools like awk, grep and perl are commonly used for this kind of problems. The cut command is a minimalistic, purpose built tool for it:



                  cut -d -f 18,19,20






                  share|improve this answer












                  General purpose commandline tools like awk, grep and perl are commonly used for this kind of problems. The cut command is a minimalistic, purpose built tool for it:



                  cut -d -f 18,19,20







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Jan 16 at 7:33









                  Heikki

                  1211




                  1211






















                       

                      draft saved


                      draft discarded


























                       


                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f416693%2fhow-to-use-grep-command-in-linux-to-filter-values-in-a-line%23new-answer', 'question_page');

                      );

                      Post as a guest













































































                      Popular posts from this blog

                      How to check contact read email or not when send email to Individual?

                      Bahrain

                      Postfix configuration issue with fips on centos 7; mailgun relay