Hi,

I'd like to generate the following awk script, where an array of
number (such as 1,3 in the following example) should be taken from the
command line. I am not familiar with m4 to make this work especially
for an array in the command line argument.

Could anybody help show me a working m4 example to generate an awk
script like this? Thanks.

==============
BEGIN {
    if(getline) {
        key1 = $1 # These two lines should be expanded
        key3 = $3 # according to the command line arguments
        value = $10
        seen_first = 1
    }
}

{
    if(key1==$1 && key3==$3) {
        # The above line should be expanded
        # according to the command line arguments
        value = value "," $10
    } else {
        print key, value
        key1 = $1 # This block should be expanded
        key3 = $3 # according to the command line arguments
        value = $10
    }
}

END {
    if(seen_first) {
        print key1, key3, value
        # The above line should be expanded
        # according to the command line arguments
    }
}
==============

-- 
Regards,
Peng

Reply via email to