Removing multiple elements from a bash array based on different patterns -


so have this:

interfaces=($(ip -o link show | awk -f': ' '{print $2}')) 

giving me array of interfaces, want remove loopback , tun adapters array.

interfaces=(${interfaces[@]/lo/}) interfaces=(${interfaces[@]/tun*/}) 

works, there way in single line?

probably super easy , derp, i'd understand how expression works (google gave me 47239432 examples of above not 1 explained how worked or gave example of using more 1 expression @ time).

i know can done awk command, both solution awk , 1 array filter appreciated :)

my apologies if stupid question.

there many ways this. 1 example:

# arr=(lo tun0 net1 net2) # echo ${arr[@]} lo tun0 net1 net2 # arr=( $( printf '%s\n' ${arr[@]} | egrep -v '^(lo|tun)' ) ) # echo ${arr[@]} net1 net2 # 

and can exclude these interfaces @ beginning:

interfaces=( $(ip -o link show | awk -f': ' '$2 !~ /^(lo|tun)/ {print $2}') ) 

Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -