SED replace the same case and minuscule occurrences with something

Asked

Viewed 266 times

0

I am trying to replace occurrences "strings that appear in the document" with another value in the '' case;

I have the following chunk of shell script code

mkdir NOVO
for script in *.sql
do 
    sed '/from/ s/fev_\|jan_//g' $script >> NOVO/$script
done

what happens is that it will only replace the occurrences "fev_" and "jan_" that are in minuscule, but there are occurrences in upper case like "FEV_" and even "Fev_" as I can automate this script to capture all these occurrences?

1 answer

1


The sed replacement command has an "I" flag that is used for regex to be case-insensitive. Do man do sed:

I i The I Modifier to regular-Expression matching is a GNU Extension which makes sed match regexp in a case-insensitive Manner.

So, you can change your command to:

sed '/from/ s/fev_\|jan_//Ig' $script >> NOVO/$script

If you want to test:

cat teste.txt linha Linha LINHA lINHA NADA

sed 's/linha/alterado/g' teste.txt alterado Linha LINHA lINHA NADA

sed 's/linha/alterado/Ig' teste.txt alterado alterado alterado alterado NADA

References:

https://www.gnu.org/software/sed/manual/html_node/The-_0022s_0022-Command.html https://stackoverflow.com/questions/16917623/use-sed-with-ignore-case-while-adding-text-before-some-pattern

  • Got it. So could you answer the question again this way? Using the link as a reference?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.