Sed one liners

From richud.com
Jump to: navigation, search

SED one liners

  • replace only with initial matching regexp (with inline replacement)
sed -i '/CONFIG_SATA/s/# \([A-Z0-9_]*\) is not set/\1=y/' .config
  • replace between two points, (grep shows changes easily, above shuld have changed, below not)

e.g. linux kernel .config file, enable all network drivers for 100mbit and gigabit

sed -e '/CONFIG_NET_ETHERNET/,/CONFIG_NETDEV_10000/s/# //' -e '/CONFIG_NET_ETHERNET/,/CONFIG_NETDEV_10000/s/ is not set/=y/' .config
sed -e '/CONFIG_NET_ETHERNET/,/CONFIG_NETDEV_10000/s/# //' -e '/CONFIG_NET_ETHERNET/,/CONFIG_NETDEV_10000/s/ is not set/=y/' .config | grep -B10 -A10 "CONFIG_NETDEV_10000"

or more concisely with inline replacement

sed -i '/CONFIG_NET_ETHERNET/,/CONFIG_NETDEV_10000/s/# \([A-Z0-9_]*\) is not set/\1=y/' .config

Fix hostPaths in Virtualbox VM's .vbox

find "~/VirtualBox VMs" -type f -iname "*.vbox" -exec sed -i "s#\/media\/7200.11\/Z_Drive#\/media\/2\/Z_Drive#" "{}" \;