Unix/Linux Go Back    

UNIX for Dummies Questions & Answers This forum is closed for new posts. Please post beginner questions to learn unix and learn linux in this forum UNIX for Beginners Questions & Answers

Egrep confusion with "I" and "-I" pattern

UNIX for Dummies Questions & Answers


Thread Tools Search this Thread Display Modes
Old Unix and Linux 07-18-2013   -   Original Discussion by VBG
VBG VBG is offline
Registered User
Join Date: Jul 2013
Last Activity: 19 July 2013, 7:08 AM EDT
Posts: 1
Thanks: 1
Thanked 0 Times in 0 Posts
Linux Egrep confusion with "I" and "-I" pattern

I am executing following command

egrep -w I filename.txt

the filename.txt has following data ....

-I 07-18 08:31:19.924 9880 6 SessionManager ConnectConfig: ConfigurationWebService LoginResults=SuccessfulLogin
I am so hungry that I need to eat

I expect egrep to print only the second line, however it prints both the lines.
Please assist.
Moderator's Comments:
Egrep confusion with "I" and "-I" pattern Please use CODE tags when displaying sample code, input, and output.

Last edited by Don Cragun; 07-18-2013 at 08:45 PM.. Reason: CODE tags
Sponsored Links
Old Unix and Linux 07-18-2013   -   Original Discussion by VBG
Don Cragun's Unix or Linux Image
Don Cragun Don Cragun is online now Forum Staff  
Join Date: Jul 2012
Last Activity: 19 November 2017, 3:43 AM EST
Location: San Jose, CA, USA
Posts: 10,657
Thanks: 571
Thanked 3,731 Times in 3,185 Posts
The -w option to grep is not specified by the standards. Some implementations of grep, egrep, and fgrep do not accept a -w option and those that do may have different ideas of what it means. A common interpretation of -w is that the given regular expression is matched if it matches a "word" where a word consists of alphanumeric and underscore characters. Since the minus sign is not in this set, the I in -I 07-18 is a match for the word I. To get the exact meaning on your OS, look at the description of the -w option on the grep(1) man page on your system.
The Following User Says Thank You to Don Cragun For This Useful Post:
VBG (07-19-2013)
Sponsored Links

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how to use "cut" or "awk" or "sed" to remove a string timmywong Shell Programming and Scripting 8 02-12-2012 12:55 PM
awk command to replace ";" with "|" and ""|" at diferent places in line of file shis100 Shell Programming and Scripting 7 03-16-2011 09:59 AM
cat $como_file | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g' harshakusam Shell Programming and Scripting 4 08-25-2009 12:21 PM
Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`" Lokesha UNIX for Dummies Questions & Answers 4 12-20-2007 01:52 AM

All times are GMT -4. The time now is 04:47 AM.