Parse interfaces from ifconfig

grep, regex, sed

Solution

I'll add this one to the pile. Add the quotes in the first sed, then just join the lines with paste.

ifconfig -a | sed -n 's/^\([^ ]\+\).*/"\1"/p' | paste -sd ","

This is better than tr since there's no trailing comma.

Better yet, since ifconfig -a output can't really be counted on to stay consistent, check /sys/class/net

ls /sys/class/net | sed -e 's/^\(.*\)$/"\1"/' | paste -sd ","

Problem

I'm trying to get the list of networks interfaces from the command-line in this form: ``` "wlan0","eth0","lo" ``` I don't need to get them in a special order. I can do this: ``` wlan0,eth0,lo ``` with this super non-optimized command, after having searched a lot and after I think I've reached my limits: ``` ifconfig -a | grep -E '' | sed -n 's/^\([^ ]\+\).*/\1/p' | tr -d '\n' | sed s/:/,/g | sed 's/.$//' ```

Original source

Related problems