grep backreferencing question


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting grep backreferencing question
# 8  
Old 10-19-2010
Well, C legality is a whole lot more than a grep! Is cc or CC making it hard to decipher?

I recommend never declaring more than 1 variable on a line. It facilitates diff and diff3 use. It gives you a distinct line number for every variable in error.
# 9  
Old 10-19-2010
It works even if I remove all the \<\> from the above code. Can you explain how?
# 10  
Old 10-19-2010
Quote:
Originally Posted by prasanna1157
>>>> Thanks lot. The only problem with the above is, it matches illegal declarations also.

like, int a,b,,b; int a,b,b,;

---------- Post updated at 02:20 PM ---------- Previous update was at 02:19 PM ----------




>>> Thanks lot. This one matches illegal declarations too.

like, int a,b,,b; int a,b,b,;
That wasn't part of your problem statement, was it? Anyway,
Code:
grep -E 'int .*([^,]+),.*\1[,\;]|int .*,[,\;]' infile


Last edited by Scrutinizer; 10-19-2010 at 05:06 PM..
# 11  
Old 10-19-2010
Without the \<\>, b matches bb.
# 12  
Old 10-19-2010
Thanks.

---------- Post updated at 02:59 PM ---------- Previous update was at 02:56 PM ----------

Quote:
Originally Posted by Scrutinizer
That wasn't part of your problem statement, was it? Anyway,
Code:
grep -E 'int .*([^,]+),.*\1[,\;]|int .*,[,\;]' infile

Code:
grep 'int .*\([^,][^,]*\),.*\1[,\;]\|int .*,[,\;]' infile

Oh, sorry. Yes, I did not state it initially.

One more question, the .* makes it match anything. But can I match only valid declarations? That is, the variables should start with alpha, can have only alphabets and numbers. Let's assume lowercase only. How do you tweak the above to check for that?

Thanks a lot.

---------- Post updated at 03:01 PM ---------- Previous update was at 02:59 PM ----------

Quote:
Originally Posted by DGPickett
Well, C legality is a whole lot more than a grep! Is cc or CC making it hard to decipher?

I recommend never declaring more than 1 variable on a line. It facilitates diff and diff3 use. It gives you a distinct line number for every variable in error.
Thanks.
So, can we not check for illegal declarations using the regex?
# 13  
Old 10-19-2010
Quote:
Originally Posted by prasanna1157
Thanks.

Oh, sorry. Yes, I did not state it initially.

One more question, the .* makes it match anything. But can I match only valid declarations? That is, the variables should start with alpha, can have only alphabets and numbers. Let's assume lowercase only. How do you tweak the above to check for that?
Hi, no the .* will not match anything, since they are embedded in context. What is your additional question? I think you question about back references is answered. If so, it may be better to start a new topic.
# 14  
Old 10-19-2010
Wrong comes in so many flavors, like integral calculus. Even right has a lot of flavors. First there are the datatypes, then the commas, the initializations, typedefs, unions, structs, Classes, code, continued lines, includes, macros.

Why not cc -c ? I hope it knows enough to catch that. There may even be c verification tools out there. Ever try lint?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Question about grep

is there anyway i can ask grep to only get the first line? as in the top command line line 1 <-- just grep this line line 2 line 3 ---------- Post updated at 04:24 PM ---------- Previous update was at 04:19 PM ---------- nvm.. found out that i can do it with |head (12 Replies)
Discussion started by: Nick1097
12 Replies

2. Shell Programming and Scripting

Question about grep

can anyone tell me what the \/$ means? from grep \/$ (8 Replies)
Discussion started by: Nick1097
8 Replies

3. Shell Programming and Scripting

Grep question

All, I am wanting to find out if I can do this in one grep statement grep -R failed * |grep -iEw 'Mar 1|Feb 2' I want to search all files in a directory for the text "failed" AND a "date or date". Currently, I am using the above running one grep and then piping it to another. It works,... (3 Replies)
Discussion started by: markdjones82
3 Replies

4. Shell Programming and Scripting

grep question

Hello, Is there a way in grep to remember patterns? For eg: int a,b,c,d,a; If a variable is declared twice, like in the previous example, I should be able to print only those lines. Is there a way to print only the lines where the variable name occurs more than once, using grep... (1 Reply)
Discussion started by: prasanna1157
1 Replies

5. UNIX for Dummies Questions & Answers

grep question

Instead of using the following command #dmesg | grep -v sendmail | grep -v xntpd How can I use just one grep -v and give both arguments. Please suggest thanks (4 Replies)
Discussion started by: Tirmazi
4 Replies

6. Programming

'Backreferencing' in SQL?

My SQL is very rust and I'm having a problem with a query. First, here are the tables involved. Table `os`: +--------------------------------+ | id | distro | version | +--------------------------------+ | 1 | CentOS | 5.2 | | 2 | RHEL | 5 | | 3 ... (1 Reply)
Discussion started by: Housni
1 Replies

7. UNIX for Dummies Questions & Answers

Grep question.

Hi, I am executing the below command. grep ".UPDATE" file1.txt | grep -v MQQUEUE > Myprog1 The expected output is all lines in file1.txt which have the string ".UPDATE" and dont contain the string MQQUEUE. However, the output which I am getting is just searching for the string... (3 Replies)
Discussion started by: saurabhsinha23
3 Replies

8. Shell Programming and Scripting

Grep question

I'm using grep in a shell and I was wondering: Can I grep a file and then delete all files that contain what it returns? So instead of grep 'blah' * and I have 50 files that have blah in it and I would have to delete all 50 manually, how would I just delete them all in one fell swoop? (3 Replies)
Discussion started by: tphegley
3 Replies

9. Shell Programming and Scripting

grep question

Hi, I am currently using grep -c to scan lines for certain data. I am just wondering if you can search a specific column of a file using grep -c. Thanks (6 Replies)
Discussion started by: Jaken
6 Replies

10. UNIX for Dummies Questions & Answers

grep question

what is the format for grep if I want to search from the current directory and through all its subdirectories?:) (3 Replies)
Discussion started by: pkappaz
3 Replies
Login or Register to Ask a Question