Case insensitive flag INSIDE an extended regexp
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
I need to perform case-insensitive match with the grepdiff tool. Unlike grep it doesn't have an argument for that, but it has --extended-regexp
. Is it possible?
I tried perl-like, but it doesn't work
$ echo SOME | egrep '(?i)some'
$ echo SOME | grepdiff --extended-regexp '(?i)some'
grepdiff: repetition-operator operand invalid
grep regular-expression
add a comment |Â
up vote
0
down vote
favorite
I need to perform case-insensitive match with the grepdiff tool. Unlike grep it doesn't have an argument for that, but it has --extended-regexp
. Is it possible?
I tried perl-like, but it doesn't work
$ echo SOME | egrep '(?i)some'
$ echo SOME | grepdiff --extended-regexp '(?i)some'
grepdiff: repetition-operator operand invalid
grep regular-expression
2
don't know aboutgrepdiff
... if it is small enough word, try[sS][oO][mM][eE]
?
â Sundeep
Feb 16 at 9:17
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I need to perform case-insensitive match with the grepdiff tool. Unlike grep it doesn't have an argument for that, but it has --extended-regexp
. Is it possible?
I tried perl-like, but it doesn't work
$ echo SOME | egrep '(?i)some'
$ echo SOME | grepdiff --extended-regexp '(?i)some'
grepdiff: repetition-operator operand invalid
grep regular-expression
I need to perform case-insensitive match with the grepdiff tool. Unlike grep it doesn't have an argument for that, but it has --extended-regexp
. Is it possible?
I tried perl-like, but it doesn't work
$ echo SOME | egrep '(?i)some'
$ echo SOME | grepdiff --extended-regexp '(?i)some'
grepdiff: repetition-operator operand invalid
grep regular-expression
edited Feb 16 at 9:16
asked Feb 16 at 9:04
basin
6781721
6781721
2
don't know aboutgrepdiff
... if it is small enough word, try[sS][oO][mM][eE]
?
â Sundeep
Feb 16 at 9:17
add a comment |Â
2
don't know aboutgrepdiff
... if it is small enough word, try[sS][oO][mM][eE]
?
â Sundeep
Feb 16 at 9:17
2
2
don't know about
grepdiff
... if it is small enough word, try [sS][oO][mM][eE]
?â Sundeep
Feb 16 at 9:17
don't know about
grepdiff
... if it is small enough word, try [sS][oO][mM][eE]
?â Sundeep
Feb 16 at 9:17
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
2
down vote
You need to tell the grep
family to use Perl-like REs.
echo SOME | grep -P '(?i)some'
SOME
Unfortunately this flag is not available in grepdiff
and, as far as I can see, neither is -i
(case insensitive match).
Here is a small script, which I've called pgrepdiff
, which will allow you to use a PCRE to match your diff
output. It does not accept any of the flags that grepdiff
allows. It reads from named files or stdin if none is provided. Omitting the RE turns it into an expensive cat
operator:
#!/bin/bash
#
# Usage: pgrepdiff <re> [<files...>]
#
# https://unix.stackexchange.com/a/424566/100397
#
tmpd=$(mktemp --tmpdir --directory 'pgd.XXXXXXXXXX')
re="$1"
shift
# Split the file into its context diff parts
cat "$@" | csplit - -f "$tmpd/xx." -k -n4 -s -z '/^@@/' '*'
# Save the header preamble for a match
mv -f "$tmpd/xx.0000" "$tmpd/head"
head=
# Iterate across all the diff segments
shopt -s nullglob
for xx in "$tmpd"/xx.????
do
if grep -q -P "$re" "$xx"
then
[[ -z $head ]] && cat "$tmpd/head" && head=yes
cat "$xx"
fi
done
# Tidy up
rm -rf "$tmpd"
# Return 0 (success) iff we matched something
[[ -n $head ]]
No,grepdiff
does not support this
â basin
Feb 16 at 9:51
@basin try the attached script
â roaima
Feb 16 at 11:00
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
You need to tell the grep
family to use Perl-like REs.
echo SOME | grep -P '(?i)some'
SOME
Unfortunately this flag is not available in grepdiff
and, as far as I can see, neither is -i
(case insensitive match).
Here is a small script, which I've called pgrepdiff
, which will allow you to use a PCRE to match your diff
output. It does not accept any of the flags that grepdiff
allows. It reads from named files or stdin if none is provided. Omitting the RE turns it into an expensive cat
operator:
#!/bin/bash
#
# Usage: pgrepdiff <re> [<files...>]
#
# https://unix.stackexchange.com/a/424566/100397
#
tmpd=$(mktemp --tmpdir --directory 'pgd.XXXXXXXXXX')
re="$1"
shift
# Split the file into its context diff parts
cat "$@" | csplit - -f "$tmpd/xx." -k -n4 -s -z '/^@@/' '*'
# Save the header preamble for a match
mv -f "$tmpd/xx.0000" "$tmpd/head"
head=
# Iterate across all the diff segments
shopt -s nullglob
for xx in "$tmpd"/xx.????
do
if grep -q -P "$re" "$xx"
then
[[ -z $head ]] && cat "$tmpd/head" && head=yes
cat "$xx"
fi
done
# Tidy up
rm -rf "$tmpd"
# Return 0 (success) iff we matched something
[[ -n $head ]]
No,grepdiff
does not support this
â basin
Feb 16 at 9:51
@basin try the attached script
â roaima
Feb 16 at 11:00
add a comment |Â
up vote
2
down vote
You need to tell the grep
family to use Perl-like REs.
echo SOME | grep -P '(?i)some'
SOME
Unfortunately this flag is not available in grepdiff
and, as far as I can see, neither is -i
(case insensitive match).
Here is a small script, which I've called pgrepdiff
, which will allow you to use a PCRE to match your diff
output. It does not accept any of the flags that grepdiff
allows. It reads from named files or stdin if none is provided. Omitting the RE turns it into an expensive cat
operator:
#!/bin/bash
#
# Usage: pgrepdiff <re> [<files...>]
#
# https://unix.stackexchange.com/a/424566/100397
#
tmpd=$(mktemp --tmpdir --directory 'pgd.XXXXXXXXXX')
re="$1"
shift
# Split the file into its context diff parts
cat "$@" | csplit - -f "$tmpd/xx." -k -n4 -s -z '/^@@/' '*'
# Save the header preamble for a match
mv -f "$tmpd/xx.0000" "$tmpd/head"
head=
# Iterate across all the diff segments
shopt -s nullglob
for xx in "$tmpd"/xx.????
do
if grep -q -P "$re" "$xx"
then
[[ -z $head ]] && cat "$tmpd/head" && head=yes
cat "$xx"
fi
done
# Tidy up
rm -rf "$tmpd"
# Return 0 (success) iff we matched something
[[ -n $head ]]
No,grepdiff
does not support this
â basin
Feb 16 at 9:51
@basin try the attached script
â roaima
Feb 16 at 11:00
add a comment |Â
up vote
2
down vote
up vote
2
down vote
You need to tell the grep
family to use Perl-like REs.
echo SOME | grep -P '(?i)some'
SOME
Unfortunately this flag is not available in grepdiff
and, as far as I can see, neither is -i
(case insensitive match).
Here is a small script, which I've called pgrepdiff
, which will allow you to use a PCRE to match your diff
output. It does not accept any of the flags that grepdiff
allows. It reads from named files or stdin if none is provided. Omitting the RE turns it into an expensive cat
operator:
#!/bin/bash
#
# Usage: pgrepdiff <re> [<files...>]
#
# https://unix.stackexchange.com/a/424566/100397
#
tmpd=$(mktemp --tmpdir --directory 'pgd.XXXXXXXXXX')
re="$1"
shift
# Split the file into its context diff parts
cat "$@" | csplit - -f "$tmpd/xx." -k -n4 -s -z '/^@@/' '*'
# Save the header preamble for a match
mv -f "$tmpd/xx.0000" "$tmpd/head"
head=
# Iterate across all the diff segments
shopt -s nullglob
for xx in "$tmpd"/xx.????
do
if grep -q -P "$re" "$xx"
then
[[ -z $head ]] && cat "$tmpd/head" && head=yes
cat "$xx"
fi
done
# Tidy up
rm -rf "$tmpd"
# Return 0 (success) iff we matched something
[[ -n $head ]]
You need to tell the grep
family to use Perl-like REs.
echo SOME | grep -P '(?i)some'
SOME
Unfortunately this flag is not available in grepdiff
and, as far as I can see, neither is -i
(case insensitive match).
Here is a small script, which I've called pgrepdiff
, which will allow you to use a PCRE to match your diff
output. It does not accept any of the flags that grepdiff
allows. It reads from named files or stdin if none is provided. Omitting the RE turns it into an expensive cat
operator:
#!/bin/bash
#
# Usage: pgrepdiff <re> [<files...>]
#
# https://unix.stackexchange.com/a/424566/100397
#
tmpd=$(mktemp --tmpdir --directory 'pgd.XXXXXXXXXX')
re="$1"
shift
# Split the file into its context diff parts
cat "$@" | csplit - -f "$tmpd/xx." -k -n4 -s -z '/^@@/' '*'
# Save the header preamble for a match
mv -f "$tmpd/xx.0000" "$tmpd/head"
head=
# Iterate across all the diff segments
shopt -s nullglob
for xx in "$tmpd"/xx.????
do
if grep -q -P "$re" "$xx"
then
[[ -z $head ]] && cat "$tmpd/head" && head=yes
cat "$xx"
fi
done
# Tidy up
rm -rf "$tmpd"
# Return 0 (success) iff we matched something
[[ -n $head ]]
edited Feb 16 at 11:00
answered Feb 16 at 9:46
roaima
39.6k545107
39.6k545107
No,grepdiff
does not support this
â basin
Feb 16 at 9:51
@basin try the attached script
â roaima
Feb 16 at 11:00
add a comment |Â
No,grepdiff
does not support this
â basin
Feb 16 at 9:51
@basin try the attached script
â roaima
Feb 16 at 11:00
No,
grepdiff
does not support thisâ basin
Feb 16 at 9:51
No,
grepdiff
does not support thisâ basin
Feb 16 at 9:51
@basin try the attached script
â roaima
Feb 16 at 11:00
@basin try the attached script
â roaima
Feb 16 at 11:00
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%2f424563%2fcase-insensitive-flag-inside-an-extended-regexp%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
2
don't know about
grepdiff
... if it is small enough word, try[sS][oO][mM][eE]
?â Sundeep
Feb 16 at 9:17