-1

On OpenWrt 10.03.1-RC6 the following command installs iptables stuff:

opkg update && grep -e "Package: iptables-mod-" -e "Package: kmod-ipt-" -e "Package: kmod-nf" -e "Package: .*nfnetlink" -e "Package: .*netfilter" -e "Package: .*iptables" /var/opkg-lists/packages | awk -F ': ' '{print $2}' | xargs opkg install

How can I make this command more compact? (For example with regular expressions.)

dash17291
  • 101
  • 3

1 Answers1

0

You can replace the grep command entirely by this grep command:

grep -E "Package: ((iptables-mod-|kmod-(ipt-|nf))|.*(nfnetlink|netfilter|iptables))" /var/opkg-lists/packages

The -E option specifies grep to use extended regular expressions. The feature of extended regular expressions I am using is:

(c|b)at 

This matches "cat" or "bat" i.e. only one of the options in the round brackets are chosen. So in your case the grep command will match

  • Package: iptables-mod-
  • Package: kmod-ipt-
  • Package: kmod-nf
  • Package: .*nfnetlink
  • Package: .*netfilter
  • Package: .*iptables

To gain better knowledge of regular expressions please use http://www.grymoire.com/Unix/Regular.html as a reference. Regular expressions form the basis of grep, sed, awk, find and many other UNIX commands. So it is a big advantage if you have a good grasp of regular expressions. Enjoy!

Chirayu Shishodiya
  • 544
  • 2
  • 7
  • 14