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
Searching all files that contain pattern ravi.sadani19 Shell Programming and Scripting 4 11-29-2008 06:52 PM
Searching for files with certain string pattern intrigue UNIX for Dummies Questions & Answers 1 02-28-2008 05:28 PM
Regarding Searching Pattern sbasetty Shell Programming and Scripting 2 09-29-2006 05:49 PM
Pattern searching inside Variable - not looking at files Rediranch UNIX for Dummies Questions & Answers 3 06-07-2005 02:07 PM
pattern searching using C giannicello High Level Programming 1 04-16-2002 12:53 PM

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 11-16-2007
murthybptl murthybptl is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 3
Pattern searching pattern in c files

I have a problem in searching a specific pattern in c files.

My requirement:

I have to find all the division operator in all cfiles.

The problem is, the multi line comments and single line comments will also have forward slash in it.

Even after avoiding these comments also, if both the division operator and the comments come in the same line, we are missing the division operator.

Please provide me the solution...

Give me some suggestions
  #2 (permalink)  
Old 11-16-2007
uvrakesh uvrakesh is offline
Registered User
  
 

Join Date: Dec 2005
Posts: 75
finding / operator

sed -n '/\/\//d; /\/\*/d ; /\*\//d ;/\//p' hello.c

This would first remove all the // comments and then /* and then */
and then from the remaining search for /

Hope this may help

Regards,
RUV
  #3 (permalink)  
Old 11-16-2007
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,293
Quote:
Code:
sed -n '/\/\//d; /\/\*/d ; /\*\//d ;/\//p' hello.c
This doesn't work if you have lines like:

Code:
a=30/6;	/* Comment */
a=10/2;	// comment
Try this:

Code:
sed -n '/[0-9a-zA-Z] *\/ *[0-9a-zA-Z]*/p' file.c
Regards
  #4 (permalink)  
Old 11-17-2007
murthybptl murthybptl is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 3
Hi franklin

What does this command actually does.....

I am not much aware of sed command.....

Please explain me clearly...


thanks
  #5 (permalink)  
Old 11-17-2007
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,293
The -n option suppresses the automatic output of input lines (that's the default).
The p at the end tells sed to output the lines that matches.

Code:
[0-9a-zA-Z] *
This searches for lines at the left side of the division operator.
The characters within the brackets search for a numeric character or a variable and the space and asteric after the brackets for zero or more spaces.

Code:
\/
This is the escaped division operator.

Code:
 *[0-9a-zA-Z]*
At the right side of the division operator we search for zero or more preceded spaces and a numeric character or a variable.

Regards

Last edited by Franklin52; 11-17-2007 at 09:50 AM.. Reason: typo
  #6 (permalink)  
Old 11-17-2007
murthybptl murthybptl is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 3
Pattern searching pattern in c files

Thank you very much.



This solution is giving all the files which is having division operator.

And at the same time giving some files which dont have division operator.

xx.c : x=y; /*** dfldkfdk **/
xx.c : return; /** dfkdfdkd **/
xx.c : /** return some value **/

can you give me any suggestion on this??

thanks & regards,
murthy.
  #7 (permalink)  
Old 11-17-2007
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,293
I placed those lines in a file and it works fine for me, I don't get those lines as output.
Have you typed the command exactly? Note the spaces before the asterics.

If you forgot them you didn't understand my explanation above.

Regards
Sponsored Links
Closed Thread

Bookmarks

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 05:41 PM.


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