Bash Sed无法将大写转换为小写

Bash Sed无法将大写转换为小写,bash,sed,Bash,Sed,我想将jSON消息中的“电子邮件地址”变量更改为小写。我尝试使用sed,但失败,因为\L选项对我不起作用。我错过什么了吗 a="{"id":null,"enabled":true,"password":"","email":"Foo@bar.com","lastName":"Foo","firstName":"lol"}" echo $a | sed -e 's/email:[[:graph:]].*,last/\L&/g' 结果表明: {id:null,enabled:true,pa

我想将jSON消息中的“电子邮件地址”变量更改为小写。我尝试使用sed,但失败,因为\L选项对我不起作用。我错过什么了吗

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

{id:null,enabled:true,password:,{L}email:Foo@bar.com,lastName:Foo,firstName:lol}
我想要的结果是:

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

我将假设您没有GNU sed,因此无法访问
\L
。相反,请尝试perl:

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

这是一个
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}

awk-F'{for(i=1;i您的代码适用于我。您可能需要指定您正在使用的操作系统以及
sed
的版本。您是否使用GNU-sed?您的代码适用于GNU-sed版本4.2.1。要了解您正在使用的版本,请使用sed--version@lifeGoGoGo
awk
是一种非常强大的文件处理工具。我建议您尝试一下。