更改文件中的字符串sed的? [英] Change a string in a file with sed?

查看:86
本文介绍了更改文件中的字符串sed的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有模板的inputfile中,如下所示。我想改变的版本:使用SED

I have a inputfile with template as shown below. I want to change the Version: using sed.

    Package: somename
    Priority: extra
    Section: checkinstall
    Maintainer: joe@example.com
    Architecture: i386
    Version: 3.1.0.2-1
    Depends:
    Provides: somename
    Description: some description

目前我使用的grep -m 1版inputfile中获取当前版本| SED的/ [:_#A-ZA-Z \\ S] * // G',我试图取代当前版本 SED的/ 3.1 .0.2-1 / 3.1.0.2 /'inputfile中

Currently I am getting the current version using grep -m 1 Version inputfile | sed 's/[:_#a-zA-Z\s"]*//g' and I am trying to replace the current version with sed 's/3.1.0.2-1/3.1.0.2/' inputfile

不过,这似乎并没有工作,但是当我使用尝试在命令行回声它的作品。
 回声'版本:3.0.9.1'| SED的/ 3.0.9.1 / 3.2.9.2 /

However this does not seem to work, but when I try it in command line using echo it works. echo 'Version: 3.0.9.1' | sed 's/3.0.9.1/3.2.9.2/'

Output: Version: 3.2.9.2

我如何能做到这一点是AP preciated任何帮助。 preferably我想改变的版本,而在该文件中获取最新版本。

Any help on how I can accomplish this would be appreciated. Preferably I would like to change the version without getting the current version in the file.

在此先感谢

推荐答案

您不需要的grep。

sed -i '/Version/s/3\.1\.0\.2-1/3.1.0.2/' <files>

这篇关于更改文件中的字符串sed的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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