2012-12-29 241 views
0

我有一个shell脚本,我正在努力,并感谢所以我现在有一个我需要的值的变量。现在我正试图弄清楚如何将变量的内容放入文件中的特定位置。Shell脚本 - 将变量的内容写入文件中的特定位置?

文件如下所示:

Package: com.chrisrjones.KegCop 
Name: KegCop 
Version: 0.0.1 
Architecture: iphoneos-arm 
Description: A frontend for the Kegboard Firmware 
Homepage: http://www.chrisrjones.com 
Depiction: http://www.chrisrjones.com 
Maintainer: Chris Jones <[email protected]> 
Author: Chris Jones <[email protected]> 
Sponsor: 
Section: Applications 

基本上我想要的输出变量已被放入该文件后的样子:

Package: com.chrisrjones.KegCop 
Name: KegCop 
Version: 0.0.1-645 
Architecture: iphoneos-arm 
Description: A frontend for the Kegboard Firmware 
Homepage: http://www.chrisrjones.com 
Depiction: http://www.chrisrjones.com 
Maintainer: Chris Jones <[email protected]> 
Author: Chris Jones <[email protected]> 
Sponsor: 
Section: Applications 

回答

0
sed -i -e "/Version/s/$/-$VAR/" filename 

编辑:

替换旧版本号(如果有的话):

sed -i -e "/Version/s/\(-...\)*$/-$VAR/" filename 
+0

非常感谢。 – Chris

+0

有没有办法我可以替换三位数字每次我运行脚本是因为现在它每次我运行脚本后追加内部版本号 – Chris

+0

即ie我有版本:0.0.1-647-647-647 – Chris