Friday, June 19, 2009

regular expression example

rpm -qa |   sed -n '/^stlinux22-/s/-[^-]*-[^-]*$//p'
substitue lines like
stlinux22-host-python-elementtree-1.2.6-1.i386
stlinux22-sh4-uclibc-busybox-links-1.2.1-5.sh4
to
stlinux22-host-python-elementtree
stlinux22-sh4-uclibc-busybox-links

/REGEXP/
     This will select any line which matches the regular expression  REGEXP.
s/REGEXP/REPLACEMENT/FLAGS
    replace REGEXP matched string to REPLACEMENT
p
  If the substitution was made, then print the new pattern space. otherwise no output on stdio.

No comments: