1

I get a syntax error:

/usr/xpg4/bin/awk: file "./test.awk": line 64: syntax error
Context is:
>>>   printf (", %s", date_value  ( $3, fmt_yyyymmdd ) );   <<<

The code fragments are:

fmt_yyyymmdd="yyyymmdd";
printf (", %s", date_value  ($22, fmt_yyyymmdd ) );

...

function date_value(string, format)
{
    return "20150101";
}

I am not able to understand where the syntax error is. A very similar statement (with one parameter only) produces no syntax error and works correctly.

printf (", %s", char_value  ( $2) );

For me it seems that awk either does not allow calling a user defined function with a parameter being a user defined variable or literal or calling a user defined function with more than one parameter. I am unfortunately not proficient in awk.

2
  • 1
    It would make it easier for us (and possibly for you) to spot your error if you put those fragments into a separate minimal example that reproduces the problem. Commented Feb 3, 2015 at 11:34
  • Is your printf inside of an action? Commented Feb 3, 2015 at 11:36

1 Answer 1

2

I think the problem is how you call the function. In user-defined functions it cannot exist any space between the name and the parameters, use:

printf (", %s", date_value($22, fmt_yyyymmdd ) );
Sign up to request clarification or add additional context in comments.

2 Comments

Yes, that is the problem, the OP is simply wrong in asserting that char_value ( $2) does not have this problem. The awk syntax for this, btw, would be printf ", %s", date_value($22, fmt_yyyymmdd) since awk is not C and so doesn't need trailing semi-colons and printf is a builtin not a function so surrounding it's args in parens is just misleading.
I have changed the code accordingly and will test it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.