Reputation: 11
Script:
read IP SIP < <(exec ifconfig en0 | awk '/inet / { t = $2; sub(/.*[.]/, "", t); print $2, t }')
I am trying to isolate the THIRD octet xxx.xxx.000.xxx and put it into a variable. Help? Thanks!
Upvotes: 1
Views: 331
Reputation: 7555
The following will set the third octet to the thirdOctet
variable:
set thirdOctet to do shell script "ifconfig en0 | awk -F . '/inet /{print $3}'"
Upvotes: 1
Reputation: 285200
Simple AppleScript solution
set ipv4Address to do shell script "ifconfig en0 | awk '/inet / {print $2}'"
set {TID, text item delimiters} to {text item delimiters, "."}
set thirdOctet to text item 3 of ipv4Address
set text item delimiters to TID
display dialog thirdOctet buttons {"OK"} default button "OK"
Upvotes: 0