Artificial intelligent assistant

Can I split on two characters, running awk only once? `ip a` produces bunch IP Addresses and interfaces status With `awk '/inet / {print $2}'`, I manage to get the IP and the subnet wolf@linux:~$ ip a | awk '/inet / {print $2}' 127.0.0.1/8 10.10.0.1/24 10.10.1.1/24 wolf@linux:~$ Then, I pipe it to another awk to remove the CIDR notation. wolf@linux:~$ ip a | awk '/inet / {print $2}' | awk -F / '{print $1}' 127.0.0.1 10.10.0.1 10.10.1.1 wolf@linux:~$ Is it possible to do this without piping the awk output to another awk? Desired Output wolf@linux:~$ ip a | <awk syntax here without additional piping> 127.0.0.1 10.10.0.1 10.10.1.1 wolf@linux:~$

For this very specific case, have you considered a better use of `ip`? For example:


ip -j -p -f inet a | awk -F \" '/local/ {print $4}'


This will print `ip address` as a JSON object an search for the `local` key, which happens to store the IP address. Is is even sharper you can use `jq`:


ip -j -p -f inet a | jq '.[].addr_info[].local'


I recommend this last command as it will not suffer from changes in `ip addr` output. However, if you really like your initial design, I would go with:


ip a | awk '/inet / {print substr($2, 1, index($2,"/")-1)}'


or


ip a | awk '/inet / {split($2, addr, "/"); print addr[1]}'


In the first command, we use `index($2, "/")` to find where `/` is in `$2` and then use `substr` to generate the substring. In the seconds one, we split `$2` on `/` and store it on `addr` array.

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy b94ddb569543b0003b06f33a3e9470a8