sed替换双引号内的内容 [英] sed replace content within double quotes

查看:91
本文介绍了sed替换双引号内的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用sed从Shell脚本替换xml文件中的versionName.

I need to replace the versionName in a xml file from a shell script using sed.

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.example.sed"
    android:versionCode="1"
    android:versionName="UNKNOWN VERSION NAME">

到目前为止,我已经搜索了包含versionName的行,但是如何告诉sed替换versionName后紧跟的双引号中的所有内容?

I've gotten so far as to search for a line containing versionName but how to tell sed to replace everything within the double quotes coming directly after versionName?

sed -i .old '/versionName/ s/WHAT TO WRITE?/NEW VERSION NAME/' AndroidManifest.xml

推荐答案

替换 not-",如下所示:

sed -i .old '/android:versionName/ s/="[^"][^"]*"/="NEW VERSION NAME"/' AndroidManifest.xml

这篇关于sed替换双引号内的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆