I need to review a logfile with Sed and cut out all the lines that start with a certain word, problem is this word begins after some amount of whitespace and unless I search for whitespace at the beginning followed by "word" I may encounter "word" somewhere legitimately hence why I don't just search for "word" only... Anyone know how to make sed accomplish this? Thanks! jlc
On Mon, Jan 05, 2009, Joseph L. Casale wrote:>I need to review a logfile with Sed and cut out all the lines that start with a certain word, problem >is this word begins after some amount of whitespace and unless I search for whitespace at the >beginning followed by "word" I may encounter "word" somewhere legitimately hence why >I don't just search for "word" only... > >Anyone know how to make sed accomplish this?There's always more than one way to do something like this: sed -n '/^[ \t]*word\s/p' /var/log/messages pcregrep '^\s*word\b' /var/log/messages awk '$1 == "word"{print}' /var/log/messages Bill -- INTERNET: bill at celestial.com Bill Campbell; Celestial Software LLC URL: http://www.celestial.com/ PO Box 820; 6641 E. Mercer Way Voice: (206) 236-1676 Mercer Island, WA 98040-0820 Fax: (206) 232-9186 It is necessary for the welfare of society that genius should be privileged to utter sedition, to blaspheme, to outrage good taste, to corrupt the youthful mind, and generally to scandalize one's uncles. -- George Bernard Shaw
On Mon, 5 Jan 2009, Joseph L. Casale wrote:> I need to review a logfile with Sed and cut out all the lines that > start with a certain word, problem is this word begins after some > amount of whitespace and unless I search for whitespace at the > beginning followed by "word" I may encounter "word" somewhere > legitimately hence why I don't just search for "word" only...The regex you want is "^[[:space:]]*word" -- Paul Heinlein <> heinlein at madboa.com <> http://www.madboa.com/
What about: perl -ne 'if (/^\s*word/) { print $_; }' logfile any others? On Mon, Jan 5, 2009 at 11:45 AM, Joseph L. Casale <JCasale at activenetwerx.com> wrote:> I need to review a logfile with Sed and cut out all the lines that start with a certain word, problem > is this word begins after some amount of whitespace and unless I search for whitespace at the > beginning followed by "word" I may encounter "word" somewhere legitimately hence why > I don't just search for "word" only... > > Anyone know how to make sed accomplish this? > > Thanks! > jlc > _______________________________________________ > CentOS mailing list > CentOS at centos.org > http://lists.centos.org/mailman/listinfo/centos >-- Thx Joshua Gimer