I would like to get the multi pattern match with implicit AND between patterns, i.e. equivalent to running several greps in a sequence:
grep pattern1 | grep pattern2 | ...
So how to convert it to something like?
grep pattern1 & pattern2 & pattern3
I would like to use single grep because I am building arguments dynamically, so everything has to fit in one string.
Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!
1. The problem statement, all variables and given/known data:
Given a text file (big_english.txt) containing roughly 250,000 words, answer the following using grep and regular expressions:
16.
Consider the grep pattern \\([a][b]\\)\\{2\\}. This should match string "abab", no? But on my Mac (MacBook Pro, 10.6.8, GNU grep 2.5.1 copyright 2001) it does not. On other machines it does match even though they claim to be running exactly the same grep. I'd appreciate any information about why I'm getting different results.
FWIW, any simpler expression works correctly on the Mac.
When using grep -r you could search in all files with either * or .
and it seems to return the same thing but is it really the same?
Let's say I search for "foo", then I could write
grep -r foo *
or
grep -r foo .
Would anyone try to explain the difference between . and *?
Hi im trying a GREP a varaiable which contains a file name and i search it in a list of .txt file and ifs its found the .txt file , it returns the name of the txt file name..the snippet im using is
Code:
foreach my $files (glob('*.txt'))
{
open(my $fh1, $files) or die("Unable to open '$files': $!");
{
if ( grep /$file/, <$fh1> )
{
$Sheet->Cells($row,$col+1)->{'Valu
I am trying to understand the difference between grep -e and grep -E.
I could see that certain patterns in the GNU Grep can be enclosed within brackets and certain others need not be.
Hi,
I'm working on a script which includes a part where i need to search for a string first using "grep" and then compare it with another variable using "if".
It should be something like
a=search pattern using grep
if [ $a = $b ]
then
..
The problem i'm facing is, in case the grep returns no result i get a syntax error in the if section.
Hi,
when I enter 'ps -ef| grep process_name'/'psu | grep process_name', i am getting multiple number of lines output( i mean multiple no of processes).how can i store it one by one and echo it in the same way(one by one).
part of script is
var1=$(remsh hostname -l username ps -ef|grep process_name |grep -v grep)
echo $var1
i am getting the output in a single line.