How to find a fixed strings with grep?
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
How to find a fixed strings with grep
if the required output is not shown with grep -F
? For example:
egrep -r 'string1|string2|string3' /var/www/http
with this what should we use?
shell-script grep
 |Â
show 3 more comments
up vote
0
down vote
favorite
How to find a fixed strings with grep
if the required output is not shown with grep -F
? For example:
egrep -r 'string1|string2|string3' /var/www/http
with this what should we use?
shell-script grep
What output with which input do you expect?
â mnille
Apr 19 at 7:11
Are you just trying to find three different strings?
â Nasir Riley
Apr 19 at 7:18
i expect the oputput of three strings but if anything like hash(#) present in the starting and ending of the string then is shows nothing otherwise the output will be those three strings
â Gurpreet kaur
Apr 19 at 7:31
Please show some sample input and desired output.
â agc
Apr 19 at 7:32
path="/home/local/abc" grep -E 'Allow from 8.8.2.5|Allow from 192.3.0.4|DenyAll'* $path if [ $? -eq 0 ]; then echohostname
echo "ftp lock (not accessable outside)" exit 0 else echohostname
echo "ftp unlock ( accessable from outside)" exit 1 fi
â Gurpreet kaur
Apr 19 at 7:36
 |Â
show 3 more comments
up vote
0
down vote
favorite
up vote
0
down vote
favorite
How to find a fixed strings with grep
if the required output is not shown with grep -F
? For example:
egrep -r 'string1|string2|string3' /var/www/http
with this what should we use?
shell-script grep
How to find a fixed strings with grep
if the required output is not shown with grep -F
? For example:
egrep -r 'string1|string2|string3' /var/www/http
with this what should we use?
shell-script grep
edited Apr 19 at 7:13
Kusalananda
102k13199315
102k13199315
asked Apr 19 at 6:58
Gurpreet kaur
61
61
What output with which input do you expect?
â mnille
Apr 19 at 7:11
Are you just trying to find three different strings?
â Nasir Riley
Apr 19 at 7:18
i expect the oputput of three strings but if anything like hash(#) present in the starting and ending of the string then is shows nothing otherwise the output will be those three strings
â Gurpreet kaur
Apr 19 at 7:31
Please show some sample input and desired output.
â agc
Apr 19 at 7:32
path="/home/local/abc" grep -E 'Allow from 8.8.2.5|Allow from 192.3.0.4|DenyAll'* $path if [ $? -eq 0 ]; then echohostname
echo "ftp lock (not accessable outside)" exit 0 else echohostname
echo "ftp unlock ( accessable from outside)" exit 1 fi
â Gurpreet kaur
Apr 19 at 7:36
 |Â
show 3 more comments
What output with which input do you expect?
â mnille
Apr 19 at 7:11
Are you just trying to find three different strings?
â Nasir Riley
Apr 19 at 7:18
i expect the oputput of three strings but if anything like hash(#) present in the starting and ending of the string then is shows nothing otherwise the output will be those three strings
â Gurpreet kaur
Apr 19 at 7:31
Please show some sample input and desired output.
â agc
Apr 19 at 7:32
path="/home/local/abc" grep -E 'Allow from 8.8.2.5|Allow from 192.3.0.4|DenyAll'* $path if [ $? -eq 0 ]; then echohostname
echo "ftp lock (not accessable outside)" exit 0 else echohostname
echo "ftp unlock ( accessable from outside)" exit 1 fi
â Gurpreet kaur
Apr 19 at 7:36
What output with which input do you expect?
â mnille
Apr 19 at 7:11
What output with which input do you expect?
â mnille
Apr 19 at 7:11
Are you just trying to find three different strings?
â Nasir Riley
Apr 19 at 7:18
Are you just trying to find three different strings?
â Nasir Riley
Apr 19 at 7:18
i expect the oputput of three strings but if anything like hash(#) present in the starting and ending of the string then is shows nothing otherwise the output will be those three strings
â Gurpreet kaur
Apr 19 at 7:31
i expect the oputput of three strings but if anything like hash(#) present in the starting and ending of the string then is shows nothing otherwise the output will be those three strings
â Gurpreet kaur
Apr 19 at 7:31
Please show some sample input and desired output.
â agc
Apr 19 at 7:32
Please show some sample input and desired output.
â agc
Apr 19 at 7:32
path="/home/local/abc" grep -E 'Allow from 8.8.2.5|Allow from 192.3.0.4|DenyAll'* $path if [ $? -eq 0 ]; then echo
hostname
echo "ftp lock (not accessable outside)" exit 0 else echo hostname
echo "ftp unlock ( accessable from outside)" exit 1 fiâ Gurpreet kaur
Apr 19 at 7:36
path="/home/local/abc" grep -E 'Allow from 8.8.2.5|Allow from 192.3.0.4|DenyAll'* $path if [ $? -eq 0 ]; then echo
hostname
echo "ftp lock (not accessable outside)" exit 0 else echo hostname
echo "ftp unlock ( accessable from outside)" exit 1 fiâ Gurpreet kaur
Apr 19 at 7:36
 |Â
show 3 more comments
3 Answers
3
active
oldest
votes
up vote
2
down vote
Either use grep -E
(the modern form for egrep
) so |
be treated as an extended regular expression alternation operator, but then you'd need to escape every other regular expression operator (like .
, ?
, *
, ^
, $
, ,
[
, (
, )
, ,
) in your fixed strings.
Or use -F
and pass the strings one per line or with several -e
s:
grep -Fe string1 -e string2 -e string3
Or:
grep -F 'string1
string2
string3'
Add the -x
option if those fixed strings have to make up the entire matched line (as opposed to be found anywhere within the line without it). Most grep
implementations also have a -w
option for word match where for instance, string1
would match inside foo string1-2
, but not inside foostring12
.
For your specific example in comments, that would be:
grep -wE 'Allow from (8.8.2.5|192.3.0.4)|DenyAll'
Or:
grep -we 'Allow from 8.8.2.5' -e 'Allow from 192.3.0.4' -e 'DenyAll'
You'd want either -w
or -x
(assuming that's the whole lines, not even spaces around) here as otherwise it would also match on lines like Allow from 8.8.2.51
.
You can also write it:
grep -xE '[[:space:]]*(Allow from (8.8.2.5|192.3.0.4)|DenyAll)[[:space:]]*'
To match on the full line (-x
) but allowing leading and trailing spacing characters (here using [[:space:]]
instead of [[:blank:]]
to also allow the CR characters found at the end of lines coming from the MS-DOS world).
To look for those fixed strings anywhere in the line but not inside comments, you'd need to ensure that the part of the line leading to those fixed strings doesn't contain #
characters. So something like:
grep -wE '^[^#]*(Allow from (8.8.2.5|192.3.0.4)|DenyAll)'
Note that the -w
there doesn't apply to Allow
as it applies to the whole matched string. So it would match on GAllow from
for instance. Some grep
implementations support <
, >
to match word boundaries explicitly (also known as b
in some):
grep -E '^[^#]*<(Allow from (8.8.2.5|192.3.0.4)|DenyAll)>'
Also note that in apache2
, configuration directives are case insensitive and any number of blanks are allowed between words. Also, I suspect you meant Deny from all
instead of DenyAll
, so maybe you'd want:
grep -iE '^[^#]*<(allow[[:blank:]]+from[[:blank:]]+(8.8.2.5|192.3.0.4)|deny[[:blank:]]+from[[:blank:]]+all)>'
add a comment |Â
up vote
0
down vote
The pipes |
need to be escaped |
like so:
grep 'string1|string2|string3' /var/www/http
The issue is that if one string contains a special character such as*
, this will not work without escaping that/those characters. You would have to insert an extra step to escape all special characters in the strings.
â Kusalananda
Apr 19 at 7:37
1
Note that|
is a GNU extension, unspecified per POSIX, not supported by allgrep
implementations.
â Stéphane Chazelas
Apr 19 at 8:41
add a comment |Â
up vote
0
down vote
The issue is that
grep -F -r 'string1|string2|string3' /var/www/http
would look for the literal string string1|string2|string3
in the files. Note, since you are looking for fixed strings, there is no reason to use egrep
(or grep -E
).
What you could do is to use
printf 'string1nstring2nstring3n' | grep -f /dev/stdin -F -r /var/www/http
This would make grep
read the fixed strings to match against from standard input (provided by printf
) and use them to get all lines that matched them in any file under the given directory.
Anything that generates a text document with the patterns on separate lines may replace the printf
above, including a simple text file (which could be read directly by grep -f textfile -F ...
).
Example from your comments:
Look for any of the strings Allow from 8.8.2.5
, Allow from 192.3.0.4
and DenyAll
in the files in $dirpath
:
printf 'Allow from 8.8.2.5nAllow from 192.3.0.4nDenyAlln' |
grep -f /dev/stdin -F -r "$dirpath"
it is not working..Is there any alternative way to do this ?
â Gurpreet kaur
Apr 19 at 7:51
@Gurpreetkaur To be able to debug your issue, I would need to know what the exact command you tried and what the result was (including error messages etc.).
â Kusalananda
Apr 19 at 8:27
add a comment |Â
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
Either use grep -E
(the modern form for egrep
) so |
be treated as an extended regular expression alternation operator, but then you'd need to escape every other regular expression operator (like .
, ?
, *
, ^
, $
, ,
[
, (
, )
, ,
) in your fixed strings.
Or use -F
and pass the strings one per line or with several -e
s:
grep -Fe string1 -e string2 -e string3
Or:
grep -F 'string1
string2
string3'
Add the -x
option if those fixed strings have to make up the entire matched line (as opposed to be found anywhere within the line without it). Most grep
implementations also have a -w
option for word match where for instance, string1
would match inside foo string1-2
, but not inside foostring12
.
For your specific example in comments, that would be:
grep -wE 'Allow from (8.8.2.5|192.3.0.4)|DenyAll'
Or:
grep -we 'Allow from 8.8.2.5' -e 'Allow from 192.3.0.4' -e 'DenyAll'
You'd want either -w
or -x
(assuming that's the whole lines, not even spaces around) here as otherwise it would also match on lines like Allow from 8.8.2.51
.
You can also write it:
grep -xE '[[:space:]]*(Allow from (8.8.2.5|192.3.0.4)|DenyAll)[[:space:]]*'
To match on the full line (-x
) but allowing leading and trailing spacing characters (here using [[:space:]]
instead of [[:blank:]]
to also allow the CR characters found at the end of lines coming from the MS-DOS world).
To look for those fixed strings anywhere in the line but not inside comments, you'd need to ensure that the part of the line leading to those fixed strings doesn't contain #
characters. So something like:
grep -wE '^[^#]*(Allow from (8.8.2.5|192.3.0.4)|DenyAll)'
Note that the -w
there doesn't apply to Allow
as it applies to the whole matched string. So it would match on GAllow from
for instance. Some grep
implementations support <
, >
to match word boundaries explicitly (also known as b
in some):
grep -E '^[^#]*<(Allow from (8.8.2.5|192.3.0.4)|DenyAll)>'
Also note that in apache2
, configuration directives are case insensitive and any number of blanks are allowed between words. Also, I suspect you meant Deny from all
instead of DenyAll
, so maybe you'd want:
grep -iE '^[^#]*<(allow[[:blank:]]+from[[:blank:]]+(8.8.2.5|192.3.0.4)|deny[[:blank:]]+from[[:blank:]]+all)>'
add a comment |Â
up vote
2
down vote
Either use grep -E
(the modern form for egrep
) so |
be treated as an extended regular expression alternation operator, but then you'd need to escape every other regular expression operator (like .
, ?
, *
, ^
, $
, ,
[
, (
, )
, ,
) in your fixed strings.
Or use -F
and pass the strings one per line or with several -e
s:
grep -Fe string1 -e string2 -e string3
Or:
grep -F 'string1
string2
string3'
Add the -x
option if those fixed strings have to make up the entire matched line (as opposed to be found anywhere within the line without it). Most grep
implementations also have a -w
option for word match where for instance, string1
would match inside foo string1-2
, but not inside foostring12
.
For your specific example in comments, that would be:
grep -wE 'Allow from (8.8.2.5|192.3.0.4)|DenyAll'
Or:
grep -we 'Allow from 8.8.2.5' -e 'Allow from 192.3.0.4' -e 'DenyAll'
You'd want either -w
or -x
(assuming that's the whole lines, not even spaces around) here as otherwise it would also match on lines like Allow from 8.8.2.51
.
You can also write it:
grep -xE '[[:space:]]*(Allow from (8.8.2.5|192.3.0.4)|DenyAll)[[:space:]]*'
To match on the full line (-x
) but allowing leading and trailing spacing characters (here using [[:space:]]
instead of [[:blank:]]
to also allow the CR characters found at the end of lines coming from the MS-DOS world).
To look for those fixed strings anywhere in the line but not inside comments, you'd need to ensure that the part of the line leading to those fixed strings doesn't contain #
characters. So something like:
grep -wE '^[^#]*(Allow from (8.8.2.5|192.3.0.4)|DenyAll)'
Note that the -w
there doesn't apply to Allow
as it applies to the whole matched string. So it would match on GAllow from
for instance. Some grep
implementations support <
, >
to match word boundaries explicitly (also known as b
in some):
grep -E '^[^#]*<(Allow from (8.8.2.5|192.3.0.4)|DenyAll)>'
Also note that in apache2
, configuration directives are case insensitive and any number of blanks are allowed between words. Also, I suspect you meant Deny from all
instead of DenyAll
, so maybe you'd want:
grep -iE '^[^#]*<(allow[[:blank:]]+from[[:blank:]]+(8.8.2.5|192.3.0.4)|deny[[:blank:]]+from[[:blank:]]+all)>'
add a comment |Â
up vote
2
down vote
up vote
2
down vote
Either use grep -E
(the modern form for egrep
) so |
be treated as an extended regular expression alternation operator, but then you'd need to escape every other regular expression operator (like .
, ?
, *
, ^
, $
, ,
[
, (
, )
, ,
) in your fixed strings.
Or use -F
and pass the strings one per line or with several -e
s:
grep -Fe string1 -e string2 -e string3
Or:
grep -F 'string1
string2
string3'
Add the -x
option if those fixed strings have to make up the entire matched line (as opposed to be found anywhere within the line without it). Most grep
implementations also have a -w
option for word match where for instance, string1
would match inside foo string1-2
, but not inside foostring12
.
For your specific example in comments, that would be:
grep -wE 'Allow from (8.8.2.5|192.3.0.4)|DenyAll'
Or:
grep -we 'Allow from 8.8.2.5' -e 'Allow from 192.3.0.4' -e 'DenyAll'
You'd want either -w
or -x
(assuming that's the whole lines, not even spaces around) here as otherwise it would also match on lines like Allow from 8.8.2.51
.
You can also write it:
grep -xE '[[:space:]]*(Allow from (8.8.2.5|192.3.0.4)|DenyAll)[[:space:]]*'
To match on the full line (-x
) but allowing leading and trailing spacing characters (here using [[:space:]]
instead of [[:blank:]]
to also allow the CR characters found at the end of lines coming from the MS-DOS world).
To look for those fixed strings anywhere in the line but not inside comments, you'd need to ensure that the part of the line leading to those fixed strings doesn't contain #
characters. So something like:
grep -wE '^[^#]*(Allow from (8.8.2.5|192.3.0.4)|DenyAll)'
Note that the -w
there doesn't apply to Allow
as it applies to the whole matched string. So it would match on GAllow from
for instance. Some grep
implementations support <
, >
to match word boundaries explicitly (also known as b
in some):
grep -E '^[^#]*<(Allow from (8.8.2.5|192.3.0.4)|DenyAll)>'
Also note that in apache2
, configuration directives are case insensitive and any number of blanks are allowed between words. Also, I suspect you meant Deny from all
instead of DenyAll
, so maybe you'd want:
grep -iE '^[^#]*<(allow[[:blank:]]+from[[:blank:]]+(8.8.2.5|192.3.0.4)|deny[[:blank:]]+from[[:blank:]]+all)>'
Either use grep -E
(the modern form for egrep
) so |
be treated as an extended regular expression alternation operator, but then you'd need to escape every other regular expression operator (like .
, ?
, *
, ^
, $
, ,
[
, (
, )
, ,
) in your fixed strings.
Or use -F
and pass the strings one per line or with several -e
s:
grep -Fe string1 -e string2 -e string3
Or:
grep -F 'string1
string2
string3'
Add the -x
option if those fixed strings have to make up the entire matched line (as opposed to be found anywhere within the line without it). Most grep
implementations also have a -w
option for word match where for instance, string1
would match inside foo string1-2
, but not inside foostring12
.
For your specific example in comments, that would be:
grep -wE 'Allow from (8.8.2.5|192.3.0.4)|DenyAll'
Or:
grep -we 'Allow from 8.8.2.5' -e 'Allow from 192.3.0.4' -e 'DenyAll'
You'd want either -w
or -x
(assuming that's the whole lines, not even spaces around) here as otherwise it would also match on lines like Allow from 8.8.2.51
.
You can also write it:
grep -xE '[[:space:]]*(Allow from (8.8.2.5|192.3.0.4)|DenyAll)[[:space:]]*'
To match on the full line (-x
) but allowing leading and trailing spacing characters (here using [[:space:]]
instead of [[:blank:]]
to also allow the CR characters found at the end of lines coming from the MS-DOS world).
To look for those fixed strings anywhere in the line but not inside comments, you'd need to ensure that the part of the line leading to those fixed strings doesn't contain #
characters. So something like:
grep -wE '^[^#]*(Allow from (8.8.2.5|192.3.0.4)|DenyAll)'
Note that the -w
there doesn't apply to Allow
as it applies to the whole matched string. So it would match on GAllow from
for instance. Some grep
implementations support <
, >
to match word boundaries explicitly (also known as b
in some):
grep -E '^[^#]*<(Allow from (8.8.2.5|192.3.0.4)|DenyAll)>'
Also note that in apache2
, configuration directives are case insensitive and any number of blanks are allowed between words. Also, I suspect you meant Deny from all
instead of DenyAll
, so maybe you'd want:
grep -iE '^[^#]*<(allow[[:blank:]]+from[[:blank:]]+(8.8.2.5|192.3.0.4)|deny[[:blank:]]+from[[:blank:]]+all)>'
edited Apr 19 at 9:19
answered Apr 19 at 8:36
Stéphane Chazelas
279k53514846
279k53514846
add a comment |Â
add a comment |Â
up vote
0
down vote
The pipes |
need to be escaped |
like so:
grep 'string1|string2|string3' /var/www/http
The issue is that if one string contains a special character such as*
, this will not work without escaping that/those characters. You would have to insert an extra step to escape all special characters in the strings.
â Kusalananda
Apr 19 at 7:37
1
Note that|
is a GNU extension, unspecified per POSIX, not supported by allgrep
implementations.
â Stéphane Chazelas
Apr 19 at 8:41
add a comment |Â
up vote
0
down vote
The pipes |
need to be escaped |
like so:
grep 'string1|string2|string3' /var/www/http
The issue is that if one string contains a special character such as*
, this will not work without escaping that/those characters. You would have to insert an extra step to escape all special characters in the strings.
â Kusalananda
Apr 19 at 7:37
1
Note that|
is a GNU extension, unspecified per POSIX, not supported by allgrep
implementations.
â Stéphane Chazelas
Apr 19 at 8:41
add a comment |Â
up vote
0
down vote
up vote
0
down vote
The pipes |
need to be escaped |
like so:
grep 'string1|string2|string3' /var/www/http
The pipes |
need to be escaped |
like so:
grep 'string1|string2|string3' /var/www/http
answered Apr 19 at 7:28
agc
4,0091935
4,0091935
The issue is that if one string contains a special character such as*
, this will not work without escaping that/those characters. You would have to insert an extra step to escape all special characters in the strings.
â Kusalananda
Apr 19 at 7:37
1
Note that|
is a GNU extension, unspecified per POSIX, not supported by allgrep
implementations.
â Stéphane Chazelas
Apr 19 at 8:41
add a comment |Â
The issue is that if one string contains a special character such as*
, this will not work without escaping that/those characters. You would have to insert an extra step to escape all special characters in the strings.
â Kusalananda
Apr 19 at 7:37
1
Note that|
is a GNU extension, unspecified per POSIX, not supported by allgrep
implementations.
â Stéphane Chazelas
Apr 19 at 8:41
The issue is that if one string contains a special character such as
*
, this will not work without escaping that/those characters. You would have to insert an extra step to escape all special characters in the strings.â Kusalananda
Apr 19 at 7:37
The issue is that if one string contains a special character such as
*
, this will not work without escaping that/those characters. You would have to insert an extra step to escape all special characters in the strings.â Kusalananda
Apr 19 at 7:37
1
1
Note that
|
is a GNU extension, unspecified per POSIX, not supported by all grep
implementations.â Stéphane Chazelas
Apr 19 at 8:41
Note that
|
is a GNU extension, unspecified per POSIX, not supported by all grep
implementations.â Stéphane Chazelas
Apr 19 at 8:41
add a comment |Â
up vote
0
down vote
The issue is that
grep -F -r 'string1|string2|string3' /var/www/http
would look for the literal string string1|string2|string3
in the files. Note, since you are looking for fixed strings, there is no reason to use egrep
(or grep -E
).
What you could do is to use
printf 'string1nstring2nstring3n' | grep -f /dev/stdin -F -r /var/www/http
This would make grep
read the fixed strings to match against from standard input (provided by printf
) and use them to get all lines that matched them in any file under the given directory.
Anything that generates a text document with the patterns on separate lines may replace the printf
above, including a simple text file (which could be read directly by grep -f textfile -F ...
).
Example from your comments:
Look for any of the strings Allow from 8.8.2.5
, Allow from 192.3.0.4
and DenyAll
in the files in $dirpath
:
printf 'Allow from 8.8.2.5nAllow from 192.3.0.4nDenyAlln' |
grep -f /dev/stdin -F -r "$dirpath"
it is not working..Is there any alternative way to do this ?
â Gurpreet kaur
Apr 19 at 7:51
@Gurpreetkaur To be able to debug your issue, I would need to know what the exact command you tried and what the result was (including error messages etc.).
â Kusalananda
Apr 19 at 8:27
add a comment |Â
up vote
0
down vote
The issue is that
grep -F -r 'string1|string2|string3' /var/www/http
would look for the literal string string1|string2|string3
in the files. Note, since you are looking for fixed strings, there is no reason to use egrep
(or grep -E
).
What you could do is to use
printf 'string1nstring2nstring3n' | grep -f /dev/stdin -F -r /var/www/http
This would make grep
read the fixed strings to match against from standard input (provided by printf
) and use them to get all lines that matched them in any file under the given directory.
Anything that generates a text document with the patterns on separate lines may replace the printf
above, including a simple text file (which could be read directly by grep -f textfile -F ...
).
Example from your comments:
Look for any of the strings Allow from 8.8.2.5
, Allow from 192.3.0.4
and DenyAll
in the files in $dirpath
:
printf 'Allow from 8.8.2.5nAllow from 192.3.0.4nDenyAlln' |
grep -f /dev/stdin -F -r "$dirpath"
it is not working..Is there any alternative way to do this ?
â Gurpreet kaur
Apr 19 at 7:51
@Gurpreetkaur To be able to debug your issue, I would need to know what the exact command you tried and what the result was (including error messages etc.).
â Kusalananda
Apr 19 at 8:27
add a comment |Â
up vote
0
down vote
up vote
0
down vote
The issue is that
grep -F -r 'string1|string2|string3' /var/www/http
would look for the literal string string1|string2|string3
in the files. Note, since you are looking for fixed strings, there is no reason to use egrep
(or grep -E
).
What you could do is to use
printf 'string1nstring2nstring3n' | grep -f /dev/stdin -F -r /var/www/http
This would make grep
read the fixed strings to match against from standard input (provided by printf
) and use them to get all lines that matched them in any file under the given directory.
Anything that generates a text document with the patterns on separate lines may replace the printf
above, including a simple text file (which could be read directly by grep -f textfile -F ...
).
Example from your comments:
Look for any of the strings Allow from 8.8.2.5
, Allow from 192.3.0.4
and DenyAll
in the files in $dirpath
:
printf 'Allow from 8.8.2.5nAllow from 192.3.0.4nDenyAlln' |
grep -f /dev/stdin -F -r "$dirpath"
The issue is that
grep -F -r 'string1|string2|string3' /var/www/http
would look for the literal string string1|string2|string3
in the files. Note, since you are looking for fixed strings, there is no reason to use egrep
(or grep -E
).
What you could do is to use
printf 'string1nstring2nstring3n' | grep -f /dev/stdin -F -r /var/www/http
This would make grep
read the fixed strings to match against from standard input (provided by printf
) and use them to get all lines that matched them in any file under the given directory.
Anything that generates a text document with the patterns on separate lines may replace the printf
above, including a simple text file (which could be read directly by grep -f textfile -F ...
).
Example from your comments:
Look for any of the strings Allow from 8.8.2.5
, Allow from 192.3.0.4
and DenyAll
in the files in $dirpath
:
printf 'Allow from 8.8.2.5nAllow from 192.3.0.4nDenyAlln' |
grep -f /dev/stdin -F -r "$dirpath"
edited Apr 19 at 8:30
answered Apr 19 at 7:24
Kusalananda
102k13199315
102k13199315
it is not working..Is there any alternative way to do this ?
â Gurpreet kaur
Apr 19 at 7:51
@Gurpreetkaur To be able to debug your issue, I would need to know what the exact command you tried and what the result was (including error messages etc.).
â Kusalananda
Apr 19 at 8:27
add a comment |Â
it is not working..Is there any alternative way to do this ?
â Gurpreet kaur
Apr 19 at 7:51
@Gurpreetkaur To be able to debug your issue, I would need to know what the exact command you tried and what the result was (including error messages etc.).
â Kusalananda
Apr 19 at 8:27
it is not working..Is there any alternative way to do this ?
â Gurpreet kaur
Apr 19 at 7:51
it is not working..Is there any alternative way to do this ?
â Gurpreet kaur
Apr 19 at 7:51
@Gurpreetkaur To be able to debug your issue, I would need to know what the exact command you tried and what the result was (including error messages etc.).
â Kusalananda
Apr 19 at 8:27
@Gurpreetkaur To be able to debug your issue, I would need to know what the exact command you tried and what the result was (including error messages etc.).
â Kusalananda
Apr 19 at 8:27
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f438657%2fhow-to-find-a-fixed-strings-with-grep%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
What output with which input do you expect?
â mnille
Apr 19 at 7:11
Are you just trying to find three different strings?
â Nasir Riley
Apr 19 at 7:18
i expect the oputput of three strings but if anything like hash(#) present in the starting and ending of the string then is shows nothing otherwise the output will be those three strings
â Gurpreet kaur
Apr 19 at 7:31
Please show some sample input and desired output.
â agc
Apr 19 at 7:32
path="/home/local/abc" grep -E 'Allow from 8.8.2.5|Allow from 192.3.0.4|DenyAll'* $path if [ $? -eq 0 ]; then echo
hostname
echo "ftp lock (not accessable outside)" exit 0 else echohostname
echo "ftp unlock ( accessable from outside)" exit 1 fiâ Gurpreet kaur
Apr 19 at 7:36