m4-discuss
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Take command line arguments to generate an awk script


From: Peng Yu
Subject: Take command line arguments to generate an awk script
Date: Sat, 24 Nov 2018 11:03:19 -0600

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

[Prev in Thread] Current Thread [Next in Thread]