From: Brian Candler Date: 2010-12-15T03:53:48+09:00 Subject: Re: Grep a string Rajesh M. wrote in post #968323: > cat /tmp/cron.list | egrep '^[0-9\*]' > 00 01 * * 0 (sync ; sync ; sync ; /sbin/reboot) > 00 18 * * 6 (sync; sync; sync; /sbin/reboot) > > Not sure it is still getting digits, what am doing wrong here? Grep shows the whole line which matches, or with the -o option shows the part of the line which matches the pattern. But you want to show the part of the line which *doesn't* match the pattern. That's why people have been suggesting using sed, which edits the line: sed 's/^[0-9* ]*//' /tmp/cron.list But who needs sed when you have ruby? ruby -pe 'sub! /^[\d* ]/,""' /tmp/cron.list However that line relies on the ugly Perlism of special default operations on $_. Better to type a few more characters and be explicit: cat /tmp/cron.list | ruby -ne 'puts $1 if /^[\d* ]+(.*)/' cat /tmp/cron.list | ruby -ne 'puts $1 if /^[\d* ]+(.*)/ =~ $_' -- Posted via http://www.ruby-forum.com/.