HI all
I have a problem, I need to replace a field in a file, but only in the lines that have some pattern, example:
100099C01101C00000000059394200701CREoperadora_TX
100099C01201C00000000000099786137OPERADORA_TX2
in the example above I need to change the first field from 1 to 2 only if the line has the CRE pattern. so the lines will be:
200099C01101C00000000059394200701CREoperadora_TX
100099C01201C00000000000099786137OPERADORA_TX2
Could you help me, how to do this with perl or with awk
Regads
Marcelo
Hi,
Check this code
echo $filename | awk '{if(index($0,"CRE") != 0)
{
if($0 ~ /^1/)
{
printf("2%s\n",substr($0,2,length($0)));
}
else
{
print $0;
}
}
else{print $0}}'
Thanks
Raghuram
anbu23
3
sed "/^1.*CRE/s/^1/2/" file
awk '/^1.*CRE/ { $1 = "2" substr($1,2) }
{ print }'