grep


grep -n '\\' tom.c works and grep -n 'stdio' tom.c works. Can I combine these two grep statements into one grep statement. I tried various ,* combinations, The computer didn't complain but it didn't offer any output either. don't know how to get a copy tom.c to you.
 
use | for or, what do you use for and??
A logical and is achieved by piping the output back as input.​
Bash:
foo | grep 'firstExpression' | grep 'secondExpression'
Should you instruct grep(1) to print additional info (after/before match context, line numbers, file names, you name it), you need to form an ersatz expression, one like covacat already suggested.​
Bash:
foo | grep -n '(firstExpression.*secondExpression|secondExpression.*firstExpression)'
Evidently this does not work isn’t straightforward if the expression may intersect each other, if a string can be part of the first and second expression at the same time.​
 
grep -n '\\' tom.c works and grep -n 'stdio' tom.c works. Can I combine these two grep statements into one grep statement. I tried various ,* combinations
Attach tom.c (as aragats requested) and tell what you would like to have matched.

don't know how to get a copy tom.c to you.
When writing a message click on the "Attach files" button (with the paperclip in front of it) at the bottom of your message.
 
Last edited:
grep -n '\\' tom.c works and grep -n 'stdio' tom.c works.
Can I combine these two grep statements into one grep statement. I tried various ,* combinations, The computer didn't complain but it didn't offer any output either.
....
i attached tom.txt
Works here with "or":
Code:
% grep '\\\|stdio' tom.c
#include<stdio.h>
 printf("%f\n",func(10.0));

% grep -E '\\|stdio' tom.c 
#include<stdio.h>
 printf("%f\n",func(10.0));
 
Back
Top