Artificial intelligent assistant

awk evaluate variable in statement I am new to `awk`, I tried numerous suggestion found online, but I cannot resolve my problem. I need variable `$number` to get evaluated inside the -F arg value. This statement works as expected: inn=$(ip ad) vth=$(echo $inn | awk -F ' 6: |@' '{print $2}') echo $vth but I need to extract this "6" and change its value accordingly, how do I do this? This is my best guess, but it is not working: inn=$(ip ad) vth=$(echo $inn | awk -vn="$number" -F ' n: |@' '{print $2}') echo $vth Update: I tried the solution, provided by @Archemar. It works great in console, but when I add it in the file, it does not work? why? how does the evaluation of the variable differs between **.sh** file and executing directly in **console**? EDIT: 1) added $inn 2) the difference between executing in console and .sh file

this rather look a shell problem, have you tried .. ?


vth=$(echo "$inn" | awk -F ' '"$number"': |@' '{print $2}')


* be sure to have your shell as a bash (e.g. first line is `#!/bin/bash` )
* if you don't need `$inn` elsewhere, use `vth=$( ip ad | ... )`
* I can't reproduce `@` in result of `ip a s` (or `ip ad` )



to catch lan interface name number `$number` I would use


vth=$(ip a s | awk -F'[: @]' -v n="$number" '$1 == n { print $3 ; exit; }' )


* * *

Note that result of `ip a s` is not meant to be parsable.

there is a `-j` option in `ip` to produce a json script that might be easier to parse with `jq` utility.

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy d999e55efc1cd0c43afe0a56e0d183c9