- 以下例為只擷取 0 ~ 9 的數字.
set a "M28SPLL1024X40R2011VTES35D121BSIRLQF"
set result [regexp -all -inline {[0-9]+} $a]
puts [concat [lrange $result 1 end-2] [lindex $result end]]
[Output]
- 1024 40 2011 121
[Scenario B]
- Capture WiFi Power Level under Linux. (such as "-45 dBm" from this example)
- Refers Linux command "iwconfig" to get necessary data as following.
wlan0 IEEE 802.11bg ESSID:"moto9A3" Nickname:"<WIFI@REALTEK>"
Mode:Managed Frequency:2.462 GHz Access Point: 00:50:BF:BB:39:A3
Bit Rate:54 Mb/s Sensitivity:0/0
Retry:off RTS thr:off Fragment thr:off
Encryption key:off
Power Management:off
Link Quality=100/100 Signal level=-45 dBm Noise level=0 dBm
Rx invalid nwid:0 Rx invalid crypt:0 Rx invalid frag:0
Tx excessive retries:0 Invalid misc:0 Missed beacon:0
Link Quality=100/100 Signal level=-45 dBm Noise level=0 dBm
set s2 "
1 {iwconfig wlan0 | grep level
Link Quality=100/100 Signal level=-45 dBm Noise level=0 dBm
root@android:/ # }
"
puts "debug: s2 =$s2"
regexp -linestop {Link Quality=100/100 Signal level=.*} $s2 WiFiRSSI1
puts "debug1: WiFiRSSI1 =$WiFiRSSI1"
set WiFiRSSI2 [string range $WiFiRSSI1 22 41]
puts "debug2: WiFiRSSI2 =$WiFiRSSI2"
set WiFiRSSI3 [string trimleft $WiFiRSSI2 "Signal level="]
puts "debug3: WiFiRSSI3 =$WiFiRSSI3"
set WiFiRSSI4 [string range $WiFiRSSI3 0 3]
puts "debug4: WiFiRSSI4 =$WiFiRSSI4"
[Output]
- debug1: WiFiRSSI1 =Link Quality=100/100 Signal level=-45 dBm Noise level=0 dBm
- debug2: WiFiRSSI2 =Signal level=-45 dBm
- debug3: WiFiRSSI3 =-45 dBm
- debug4: WiFiRSSI4 =-45
沒有留言:
張貼留言