Sed cannot convert upper case to lower case

I want to change the variance of the "email address" in the lower case jSON message. I tried using sed, but could not, as the \ L option does not work for me. Did I miss something?

a="{"id":null,"enabled":true,"password":"","email":"Foo@bar.com","lastName":"Foo","firstName":"lol"}"
echo $a | sed -e 's/email:[[:graph:]].*,last/\L&/g'

Result:

{id:null,enabled:true,password:,{L}email:Foo@bar.com,lastName:Foo,firstName:lol}

As a result, I want:

{id:null,enabled:true,password:,email:foo@bar.com,lastName:Foo,firstName:lol}
+4
source share
2 answers

I am going to assume that you do not have GNU sed and therefore no access to \L. Try perl instead:

echo "$a" | perl -pe 's/(email:[[:graph:]]*,last)/\L\1/'
+3
source

Here awk

awk -F, '{for (i=1;i<=NF;i++) if ($i~/email/) $i=tolower($i)}1' <<< "$a"
{id:null enabled:true password: email:foo@bar.com lastName:Foo firstName:lol}
+1
source

All Articles