Results 1 to 3 of 3
Hi,
I need some help writing a regular expression.
I'm doing:
Code:
modprobes=(`modprobe -l`)
for filename in "${modprobes[@]}"
do
echo $filename
done
This outputs the likes of:
/lib/modules/2.6.24-23-generic/ubuntu/net/et131x/et131x.ko
/lib/modules/2.6.24-23-generic/ubuntu/net/e1000e-ich9m/e1000e-ich9m.ko
/lib/modules/2.6.24-23-generic/ubuntu/net/atl2/atl2.ko
...
- 03-07-2009 #1Just Joined!
- Join Date
- Dec 2007
- Posts
- 6
Bash scripting substring
Hi,
I need some help writing a regular expression.
I'm doing:
This outputs the likes of:Code:modprobes=(`modprobe -l`) for filename in "${modprobes[@]}" do echo $filename done
/lib/modules/2.6.24-23-generic/ubuntu/net/et131x/et131x.ko
/lib/modules/2.6.24-23-generic/ubuntu/net/e1000e-ich9m/e1000e-ich9m.ko
/lib/modules/2.6.24-23-generic/ubuntu/net/atl2/atl2.ko
/lib/modules/2.6.24-23-generic/ubuntu/net/igb/igb.ko
/lib/modules/2.6.24-23-generic/ubuntu/acpi/acer_acpi/wmi-acer.ko
/lib/modules/2.6.24-23-generic/ubuntu/acpi/acer_acpi/acer_acpi.ko
/lib/modules/2.6.24-23-generic/ubuntu/block/drbd/drbd.ko
/lib/modules/2.6.24-23-generic/ubuntu/block/iscsitarget/iscsi_trgt.ko
/lib/modules/2.6.24-23-generic/ubuntu/hwmon/hdaps_ec.ko
/lib/modules/2.6.24-23-generic/ubuntu/misc/pbe5.ko
/lib/modules/2.6.24-23-generic/ubuntu/misc/nozomi.ko
/lib/modules/2.6.24-23-generic/ubuntu/misc/thinkpad_ec.ko
/lib/modules/2.6.24-23-generic/ubuntu/misc/fsc_btns.ko
/lib/modules/2.6.24-23-generic/ubuntu/misc/av5100.ko
/lib/modules/2.6.24-23-generic/ubuntu/misc/ndiswrapper/ndiswrapper.ko
Instead of echoing this, I want to match the name of the module. So, for /lib/modules/2.6.24-23-generic/ubuntu/misc/ndiswrapper/ndiswrapper.ko I want to echo ndiswrapper.
Could someone help? I know its pretty basic but I am new to bash and regexes
Thanks,
Stephen
- 03-07-2009 #2Just Joined!
- Join Date
- Feb 2009
- Posts
- 45
You probably want this:
Originally Posted by sroberts82
You can apply «sed» in the same way to your version of the code. But I think the principle should be clear.Code:modprobe -l | sed -e 's/.*\/\(.*\).ko/\1/';
- 03-07-2009 #3
or:
modprobes=(`modprobe -l`)
for filename in "${modprobes[@]}"
do
awk '{FS="."; print $1;}' `basename $filename`
done


Reply With Quote