I will try to explain better. I also checked the comments but still dont have luck with the replace.
grep part is returning true, because the regexp seems to be ok. But sed, doesnt replace
This is the script:
#!/bin/bash
# All of these:
# FILE1: &VAR1 = 1111
# FILE1: &VAR1 = '1111'
# FILE1: &VAR1 = 1111;
# With:
# &VAR2 = 'NEW';
#
# SEARCH STRING
LAREXP="&VAR1\s*=\s*'?[1]{4}'?"
# REPLACE STRING
LACADE="&VAR2 = 'NEW'";
# ALL FILES WITH NAME STARTING WITH ZZ
for f in /home/u028619/zz*; do
# SEARCH IF THE SEARCH STRING EXISTS, THIS IS ALWAYS TRUE, OK
if grep -qE "$LAREXP" "$f"; then
# REPLACE THE STRING, THIS IS WHATS DOESN'T WORK
sed -i "s/$LAREXP/$LACADE/g" "$f"
fi
done
#
exit 0