示例json文件file.json内容如下, [{"name":"张国立","sex":"男","email":"[email protected]","url":"./img/1.jpg"},{"name":"张铁林","sex":"男","email":"[email protected]","url":"./img/2.jpg"},{"name":"邓婕","sex":"女","email":"[email protected]","url":"./img/3.jpg"},{"name":"张国立","sex":"男","email":"[email protected]","url":"./img/4.jpg"},{"name":"张铁林","sex":"男","email":"[email protected]","url":"./img/5.jpg"},{"name":"邓婕","sex":"女","email":"[email protected]","url":"./img/6.jpg"}] 假设要修改url字段值,用一个变量代替,shell命令如下, (py3813) pc@C01:~$ as=”0000000364.jpeg” ; sed -E -e ‘s/”name”:[ \t]{0,}”[^”]+jpe?g”/””:'”$as”‘/g’ -e ‘s/”source”:[ \t]{0,}”[^”]+jpe?g”/”source”:'”$as”‘/g’ file.json [{“name”:”张国立”,”sex”:”男”,”email”:”[email protected]”,”url”:”./img/1.jpg”},{“name”:”张铁林”,”sex”:”男”,”email”:”[email protected]”,”url”:”./img/2.jpg”},{“name”:”邓婕”,”sex”:”女”,”email”:”[email protected]”,”url”:”./img/3.jpg”},{“name”:”张国立”,”sex”:”男”,”email”:”[email protected]”,”url”:”./img/4.jpg”},{“”:0000000364.jpeg,”sex”:”男”,”email”:”[email protected]”,”source”:0000000364.jpeg},{“”:0000000364.jpeg,”source”:0000000364.jpeg,”email”:”[email protected]”,”url”:”./img/5.jpg”},{“name”:”邓婕”,”sex”:”女”,”email”:”[email protected]”,”url”:”./img/6.jpg”}]