0

我在 2 个不同的路径中有 2 个文件。我想将安装版本从 file1 复制到 file2

文件 1: VersionInfo.Properties:

Installed Version:13.9.0-9
Previous Version:13.8.0-2

文件 2:Install.sh

  #!/bin/bash
    --- #some content is there
    ----
   uninstall_and_install_rpm component 13.7.0-3
   -----
    ------

期望的输出:

文件 2:Install.sh

  #!/bin/bash
    --- #some content is there
    ----
   uninstall_and_install_rpm component 13.9.0-9
   -----
    ------
4

1 回答 1

2
awk '
    NR == FNR {
        split($0,a,":")
        if (a[1] == "Installed Version") ver = a[2]
        next
    }
    /uninstall_and_install_rpm/ {$NF = ver}
    1
' VersionInfo.Properties Install.sh > Install.sh.new &&
mv Install.sh Install.sh.old &&
mv Install.sh.new Install.sh
于 2013-09-12T15:39:56.900 回答