Your grep is "too anchored" and your regex visualization is too wild. There is no back referencing in regex, just iteratively forward testing: '.*' means try remainder of pattern at every following byte.
A line containing the word int and later a semicolon should not have any variable-legal word repeated between them. Every variable name in C must start with a letter, the rest of the name can consist of letters, numbers and underscore characters. Commas are not variable-legal words, so you can ignore them -- classic excess information problem.
Deal with white spaces using \<\> or similar word boundary, so you avoid substrings but do not get tangled in the whole comma, space, tab thing. Some grep do not honor '\<\>' so you may need sed or '\b'.
If you get desperate, add spaces by commas and semicolon so you can look for space or tab [ \t]. If you need to restore the original, sed has a hold space h/g command pair.
>>>> 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 ----------
Quote:
Originally Posted by Scrutinizer
---------- Post updated at 19:37 ---------- Previous update was at 19:32 ----------
Normal grep:
>>> Thanks lot. This one matches illegal declarations too.
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)
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)
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)
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)
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)
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)
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)
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)