The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-19-2008
askumarece askumarece is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 26
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..
  #2 (permalink)  
Old 02-19-2008
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,717
I must be missing something:
Code:
grep 'package com.att.com;' file
does what you ask? It will find 'package com.att.com;' anywhere in the line of text.
  #3 (permalink)  
Old 02-19-2008
askumarece askumarece is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 26
Quote:
Originally Posted by jim mcnamara View Post
I must be missing something:
Code:
grep 'package com.att.com;' file
does what you ask? It will find 'package com.att.com;' anywhere in the line of text.
Jim,
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..
  #4 (permalink)  
Old 02-19-2008
Lukeadams Lukeadams is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 4
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.
  #5 (permalink)  
Old 02-19-2008
askumarece askumarece is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 26
I want to grep for the lines w/ spaces before the words. Can you give me the grep command for this?
  #6 (permalink)  
Old 02-19-2008
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,717
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
You need to be ultra-specific in asking for what you want.
Closed Thread

Bookmarks

Tags
solaris

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 02:20 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0