Alex Kazmierski
Alex Kazmierski

Reputation: 11

Isolate the THIRD octet from an IP address and put it in a variable. This line is doing the 4th. macOS/AppleScript/Automator using /bin/bash

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

Answers (2)

user3439894
user3439894

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

vadian
vadian

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

Related Questions