Reputation: 1124
I want to change the "email address" variance in a jSON message to lowercase. I tried to use sed but failed, since the \L option does not work for me. Did I miss something?
a="{"id":null,"enabled":true,"password":"","email":"[email protected]","lastName":"Foo","firstName":"lol"}"
echo $a | sed -e 's/email:[[:graph:]].*,last/\L&/g'
The result shows:
{id:null,enabled:true,password:,{L}email:[email protected],lastName:Foo,firstName:lol}
The result I want:
{id:null,enabled:true,password:,email:[email protected],lastName:Foo,firstName:lol}
Upvotes: 4
Views: 131
Reputation: 41460
Here is an awk
awk -F, '{for (i=1;i<=NF;i++) if ($i~/email/) $i=tolower($i)}1' <<< "$a"
{id:null enabled:true password: email:[email protected] lastName:Foo firstName:lol}
Upvotes: 1
Reputation: 113994
I am going to assume that you do not have GNU sed and therefore do not have access to \L
. Instead, try perl:
echo "$a" | perl -pe 's/(email:[[:graph:]]*,last)/\L\1/'
Upvotes: 3