You need to sign in or sign up before continuing.
qemucapsfixreplies 519 字节
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
#!/bin/sh

if [ "$#" -ne 1 ] || [ "$1" = "--help" ] || [ ! -f "$1" ]; then
    echo "This script fixes replies ids in QEMU replies files."
    echo ""
    echo "      Usage: $0 path/to/qemu.replies"
    exit 0
fi

awk -i inplace \
    'BEGIN {count=1; pattern="libvirt-[0-9]+"}
    {
        if (match($0, "libvirt-1[^0-9]")) {
            count=1;
        }
        if (match($0, pattern)) {
            str="libvirt-" count;
            sub(pattern, str, $0);
            count++;
        }
        print
    }' "$1"