egrep help required to find pattern


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting egrep help required to find pattern
# 1  
Old 04-18-2011
egrep help required to find pattern

Hi All,

Can some one please help me how to grep the comments from "oracle" & "sybase" code. I would like to grep below type of pattern.
Code:
--
/* */

Please help.
# 2  
Old 04-18-2011
Code:
grep -E '/\*.*\*/|\-\-' file

or if you have multi-line /* */ comments:
Code:
awk '/\/\*.*\*\// || /\/\*/,/\*\//{print}/--/' file


Last edited by kato; 04-18-2011 at 09:10 AM..
# 3  
Old 04-18-2011
Another one:
Code:
awk '/--/;/\/\*/{p=1};p;/\*\//{p=0}' file

# 4  
Old 04-18-2011
Thanks a lot for your quick revert.

Is it possible to find the pattern in between some sting like below,

Code:
/*
xyz xyz
xyz xyx
*/

For eg. need to exclude evrything between starting "/*" & ending "*/", please advise.
# 5  
Old 04-18-2011
Quote:
Originally Posted by gr8_usk
Thanks a lot for your quick revert.

Is it possible to find the pattern in between some sting like below,

Code:
/*
xyz xyz
xyz xyx
*/

For eg. need to exclude evrything between starting "/*" & ending "*/", please advise.
This command should do the job:
Code:
awk '/--/;/\/\*/{p=1};p;/\*\//{p=0}' file

This is the output I get:
Code:
$ cat file
Tue Mar 25 23:35:00 GMT 2008
-- COMMENT Tue Mar 25 21:34:23 GMT 2008
Tue Mar 25 18:18:10 GMT 2008
/* COMMENT Mon Mar 26 15:54:13 GMT 2008 */
Mon Mar 26 13:21:40 GMT 2001
Mon Mar 26 13:21:40 GMT 2002
/*
COMMENT Mon Mar 26 13:21:40 GMT 2003
COMMENT Mon Mar 26 13:21:40 GMT 2004
*/
$ 
$ awk '/--/;/\/\*/{p=1};p;/\*\//{p=0}' file
-- COMMENT Tue Mar 25 21:34:23 GMT 2008
/* COMMENT Mon Mar 26 15:54:13 GMT 2008 */
/*
COMMENT Mon Mar 26 13:21:40 GMT 2003
COMMENT Mon Mar 26 13:21:40 GMT 2004
*/

This User Gave Thanks to Franklin52 For This Post:
# 6  
Old 05-04-2011
Thanks all for your help. One last question how can I exclude the pattern searched by below code,

Code:
awk '/--/;/\/\*/{p=1};p;/\*\//{p=0}' file

# 7  
Old 05-04-2011
Quote:
Originally Posted by gr8_usk
Thanks all for your help. One last question how can I exclude the pattern searched by below code,

Code:
awk '/--/;/\/\*/{p=1};p;/\*\//{p=0}' file

Something like this?
Code:
awk '/--/{next};/\/\*/{p=1};!p;/\*\//{p=0}' file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

EGREP pattern advice

Hi, I need advice on a simiple pattern check, Orginal Code bpimagelist -backupid xxxxxxxxxxxxx | grep "FRAG " | egrep -i "C5|W5" | awk 'NR==1{print $2,$9} 1 MAC514 What i want is to find any media beinging with C5|W5. I have tried ^C5|^W5, but this does not work. Removed... (3 Replies)
Discussion started by: Junes
3 Replies

2. Shell Programming and Scripting

Help required to find pattern

Hi All, I have a oracle code & want to exclude the comments present in the code. Below may be the pattern can be considered for eg. -- ALTER TABLE ALTER TABLE -- To create In above sample, First line is full commented line as it starts with "--" Wheras the second line is starting... (2 Replies)
Discussion started by: gr8_usk
2 Replies

3. Shell Programming and Scripting

Find required files by pattern in xml files and the change the pattern on Linux

Hello, I need to find all *.xml files that matched by pattern on Linux. I need to have written the file name on the screen and then change the pattern in the file just was found. For instance. I can start the script with arguments for keyword and for value, i.e script.sh keyword... (1 Reply)
Discussion started by: yart
1 Replies

4. Shell Programming and Scripting

egrep - Help Required

HI, I have a piece of code which checks the return value for a pattern "Status: 0000" like this - returnval=<<some op>> echo $returnval | egrep "\bStatus:\s+" if ; then echo "Failed" fi Even on success or failure i get $? = 1 i.e. it never passes ? (16 Replies)
Discussion started by: angshuman_ag
16 Replies

5. Shell Programming and Scripting

How to egrep multiple pattern

Hi everyone i want to write a script to grep multiple pattern from all the file from a dir. for example I want to get all the record number from XML file who's last name is asd, smith, dfrt,gokul,and sinha. I tried egrep('sinha'|'gokul'|'asd') but it is not working also i tried saving... (2 Replies)
Discussion started by: revertback
2 Replies

6. Shell Programming and Scripting

grep/egrep end of pattern

Hi I use arp to get the mac-addresses of my hosts. # arp -a | grep 192.168.0. e1000g0 192.168.0.1 255.255.255.255 o 00:00:00:00:00:01 e1000g0 192.168.0.11 255.255.255.255 o 00:00:00:00:00:02 e1000g0 192.168.0.2 255.255.255.255 ... (12 Replies)
Discussion started by: domi55
12 Replies

7. Shell Programming and Scripting

Simple egrep pattern

I'm new to egrep. What pattern could I use to find all lines that match this pattern: <beginning of line><any amount of whitespace>sub<space>. I want it to return the entire line. (I'm trying to generate a list of all Perl sub definitions in a list of Perl modules.) Thanks for your help! (7 Replies)
Discussion started by: blondie53403
7 Replies

8. UNIX for Advanced & Expert Users

Urgent Help required : awk/sed help to find pattern and delete till end of line

Hi, I need help with using an awk or sed filter on the below line ALTER TABLE "ACCOUNT" ADD CONSTRAINT "ACCOUNT_PK" PRIMARY KEY ("ACCT_ID") USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 STORAGE(INITIAL 65536 FREELISTS 1 FREELIST GROUPS 1) TABLESPACE "WMC_DATA" LOGGING ENABLE Look for... (1 Reply)
Discussion started by: rajan_san
1 Replies

9. Shell Programming and Scripting

HOW to egrep fo a pattern

Hi, I want to use egrep to match this expression in my file. The expression begins with the word SCHEDULE and ends with PFTDGNIN. In between these 2 words there can be anything. EX: Line1: SCHEDULE NWERRR#PFTDGNIN Line2: FOLLOWS NWD@AAS#PFTDGNIN So as a result of the egrep command... (1 Reply)
Discussion started by: eliewadi
1 Replies

10. UNIX for Dummies Questions & Answers

egrep a certain pattern

hey guys this is my first post here, heard a lot about these forums. Iam urgently in need of a command which would help me accomplish the following , for example a file has these contents: 211 61 2007-06-26 13:47:32 211 61 2007-06-26 09:53:43 211 61 2007-06-26 15:25:14 211 61 2007-06-26... (5 Replies)
Discussion started by: trust123
5 Replies
Login or Register to Ask a Question