![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| grep for pattern | aemunathan | Shell Programming and Scripting | 12 | 05-09-2008 02:58 AM |
| help with grep the pattern | bluemoon1 | Shell Programming and Scripting | 2 | 09-20-2007 11:27 AM |
| unable to grep the following pattern | suri | Shell Programming and Scripting | 2 | 03-07-2007 03:03 AM |
| grep for more than one pattern | frustrated1 | Shell Programming and Scripting | 4 | 12-13-2005 01:49 PM |
| search pattern by grep | vijaysabari | Shell Programming and Scripting | 3 | 06-23-2004 03:03 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
How to grep this pattern??
Hi All,
I have a file like this, from this file I want to grep only this "package com.att.com;".... even though spaces are present at starting of the line. i.e., the o/p should ignore these two lines from the file : [space] [space] asdasdasd package ; ignore this line [space] asdasdasd adsfkl90-9-0 package c.com; ignore this line also Here it is the file content : ------------------------ package com.att.com; [space] package com.att.com; [double space] package com.att.com; [space] package com.att.com; [space] [space] package com.att.com; package com.att.com; package com.att.com; package com.att.com; package com.att.com; [space] [space] asdasdasd package ; ignore this line [space] asdasdasd adsfkl90-9-0 package c.com; ignore this line also package com.att.com; ------------------------ thanks, saravana Last edited by askumarece; 02-19-2008 at 02:22 PM.. |
|
||||
|
Quote:
But it will miss the lines which are having spaces b4 "package com.att.com;" I need to grep that also..... Last edited by askumarece; 02-19-2008 at 02:26 PM.. |
|
||||
|
I think you just need to add the "beginning of a line" character to only grep the lines that have no spaces before them.
grep '^package com.att.com;' file Works in Solaris. Your wording is a little confusing... normally when grep is used as a verb, at least in my experience, it means "get the lines that include". So if I want to find the lines in a dcoument that has the word foo them, I say "I want to grep for foo" So... do you want to grep for the lines w/ spaces before the words or only those without spaces before the words? Do include in the output the lines w/ spaces before, use the first example provided by Jim. If you want to exclude the lines w/ spaces before the text from your output, use the one I provided. Cheers. |
|
||||
|
Code:
# one space in front of it anywhere on the line grep ' package com.att.com;' file # one or more white spaces grep '[ \t]*package com.att.com;' file # at the beginning of the line grep '^ package com.att.com;' file # one or more spaces at the beginning grep '^[ \t]*package com.att.com;' file # one or more spaces where it is at the end of the line grep '[ \t]*package com.att.com;$' file |
![]() |
| Bookmarks |
| Tags |
| solaris |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|