Case insensitive flag INSIDE an extended regexp

The name of the pictureThe name of the pictureThe name of the pictureClash 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






share|improve this question


















  • 2




    don't know about grepdiff... if it is small enough word, try [sS][oO][mM][eE]?
    – Sundeep
    Feb 16 at 9:17















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






share|improve this question


















  • 2




    don't know about grepdiff... if it is small enough word, try [sS][oO][mM][eE]?
    – Sundeep
    Feb 16 at 9:17













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






share|improve this question














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








share|improve this question













share|improve this question




share|improve this question








edited Feb 16 at 9:16

























asked Feb 16 at 9:04









basin

6781721




6781721







  • 2




    don't know about grepdiff... if it is small enough word, try [sS][oO][mM][eE]?
    – Sundeep
    Feb 16 at 9:17













  • 2




    don't know about grepdiff... 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











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 ]]





share|improve this answer






















  • No, grepdiff does not support this
    – basin
    Feb 16 at 9:51










  • @basin try the attached script
    – roaima
    Feb 16 at 11:00










Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);








 

draft saved


draft discarded


















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






























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 ]]





share|improve this answer






















  • No, grepdiff does not support this
    – basin
    Feb 16 at 9:51










  • @basin try the attached script
    – roaima
    Feb 16 at 11:00














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 ]]





share|improve this answer






















  • No, grepdiff does not support this
    – basin
    Feb 16 at 9:51










  • @basin try the attached script
    – roaima
    Feb 16 at 11:00












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 ]]





share|improve this answer














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 ]]






share|improve this answer














share|improve this answer



share|improve this answer








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
















  • 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












 

draft saved


draft discarded


























 


draft saved


draft discarded














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













































































Popular posts from this blog

How to check contact read email or not when send email to Individual?

Displaying single band from multi-band raster using QGIS

How many registers does an x86_64 CPU actually have?