setting more variables insite awk if ? :
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
I get error in such simple test with two variables:
$ echo test|awk '$2 != ""? o="ABC" r="123" : o="123 r="ABC"ENDprint "o:"o" r:"r'
awk: cmd. line:1: $2 != ""? o="ABC" r="123" : o="123 r="ABC"ENDprint "o:"o" r:"r
awk: cmd. line:1: ^ syntax error
awk: cmd. line:1: $2 != ""? o="ABC" r="123" : o="123 r="ABC"ENDprint "o:"o" r:"r
awk: cmd. line:1: ^ syntax error
awk: cmd. line:1: $2 != ""? o="ABC" r="123" : o="123 r="ABC"ENDprint "o:"o" r:"r
awk: cmd. line:1: ^ unterminated string
$
with single variables it works fine:
$ echo test|awk '$1 != ""? o="ABC" : o="123"ENDprint "o:"o'
o:ABC
$ echo test|awk '$2 != ""? o="ABC" : o="123"ENDprint "o:"o'
o:123
awk gawk
add a comment |Â
up vote
0
down vote
favorite
I get error in such simple test with two variables:
$ echo test|awk '$2 != ""? o="ABC" r="123" : o="123 r="ABC"ENDprint "o:"o" r:"r'
awk: cmd. line:1: $2 != ""? o="ABC" r="123" : o="123 r="ABC"ENDprint "o:"o" r:"r
awk: cmd. line:1: ^ syntax error
awk: cmd. line:1: $2 != ""? o="ABC" r="123" : o="123 r="ABC"ENDprint "o:"o" r:"r
awk: cmd. line:1: ^ syntax error
awk: cmd. line:1: $2 != ""? o="ABC" r="123" : o="123 r="ABC"ENDprint "o:"o" r:"r
awk: cmd. line:1: ^ unterminated string
$
with single variables it works fine:
$ echo test|awk '$1 != ""? o="ABC" : o="123"ENDprint "o:"o'
o:ABC
$ echo test|awk '$2 != ""? o="ABC" : o="123"ENDprint "o:"o'
o:123
awk gawk
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I get error in such simple test with two variables:
$ echo test|awk '$2 != ""? o="ABC" r="123" : o="123 r="ABC"ENDprint "o:"o" r:"r'
awk: cmd. line:1: $2 != ""? o="ABC" r="123" : o="123 r="ABC"ENDprint "o:"o" r:"r
awk: cmd. line:1: ^ syntax error
awk: cmd. line:1: $2 != ""? o="ABC" r="123" : o="123 r="ABC"ENDprint "o:"o" r:"r
awk: cmd. line:1: ^ syntax error
awk: cmd. line:1: $2 != ""? o="ABC" r="123" : o="123 r="ABC"ENDprint "o:"o" r:"r
awk: cmd. line:1: ^ unterminated string
$
with single variables it works fine:
$ echo test|awk '$1 != ""? o="ABC" : o="123"ENDprint "o:"o'
o:ABC
$ echo test|awk '$2 != ""? o="ABC" : o="123"ENDprint "o:"o'
o:123
awk gawk
I get error in such simple test with two variables:
$ echo test|awk '$2 != ""? o="ABC" r="123" : o="123 r="ABC"ENDprint "o:"o" r:"r'
awk: cmd. line:1: $2 != ""? o="ABC" r="123" : o="123 r="ABC"ENDprint "o:"o" r:"r
awk: cmd. line:1: ^ syntax error
awk: cmd. line:1: $2 != ""? o="ABC" r="123" : o="123 r="ABC"ENDprint "o:"o" r:"r
awk: cmd. line:1: ^ syntax error
awk: cmd. line:1: $2 != ""? o="ABC" r="123" : o="123 r="ABC"ENDprint "o:"o" r:"r
awk: cmd. line:1: ^ unterminated string
$
with single variables it works fine:
$ echo test|awk '$1 != ""? o="ABC" : o="123"ENDprint "o:"o'
o:ABC
$ echo test|awk '$2 != ""? o="ABC" : o="123"ENDprint "o:"o'
o:123
awk gawk
asked Mar 22 at 21:32
DonJ
768
768
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
3
down vote
You can't really do that with the ? :
operator, since it can handle a single value only, and two assignments would generate two values.
Use an actual if
statement instead:
$ echo test|awk ' if ($2 != "") o="ABC"; r="123" else o="123"; r="ABC" END print "o:"o" r:"r'
o:123 r:ABC
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
You can't really do that with the ? :
operator, since it can handle a single value only, and two assignments would generate two values.
Use an actual if
statement instead:
$ echo test|awk ' if ($2 != "") o="ABC"; r="123" else o="123"; r="ABC" END print "o:"o" r:"r'
o:123 r:ABC
add a comment |Â
up vote
3
down vote
You can't really do that with the ? :
operator, since it can handle a single value only, and two assignments would generate two values.
Use an actual if
statement instead:
$ echo test|awk ' if ($2 != "") o="ABC"; r="123" else o="123"; r="ABC" END print "o:"o" r:"r'
o:123 r:ABC
add a comment |Â
up vote
3
down vote
up vote
3
down vote
You can't really do that with the ? :
operator, since it can handle a single value only, and two assignments would generate two values.
Use an actual if
statement instead:
$ echo test|awk ' if ($2 != "") o="ABC"; r="123" else o="123"; r="ABC" END print "o:"o" r:"r'
o:123 r:ABC
You can't really do that with the ? :
operator, since it can handle a single value only, and two assignments would generate two values.
Use an actual if
statement instead:
$ echo test|awk ' if ($2 != "") o="ABC"; r="123" else o="123"; r="ABC" END print "o:"o" r:"r'
o:123 r:ABC
answered Mar 22 at 21:46
Filipe Brandenburger
3,461621
3,461621
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f432941%2fsetting-more-variables-insite-awk-if%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password