How to get a count of variables passed to awk
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
I am trying to invoke awk inside a bash script and passing some bash variables values to it. Is there any way to get a count of these variables and print all which are passed to it inside awk.
No. of variables passed to awk would be dynamic.
Below example
#!/bin/bash
NAME="Dell"
SERIAL="12345"
echo "Hello" | awk -v a=$NAME -v b=$SERIAL ' print a,b '
bash awk
add a comment |Â
up vote
0
down vote
favorite
I am trying to invoke awk inside a bash script and passing some bash variables values to it. Is there any way to get a count of these variables and print all which are passed to it inside awk.
No. of variables passed to awk would be dynamic.
Below example
#!/bin/bash
NAME="Dell"
SERIAL="12345"
echo "Hello" | awk -v a=$NAME -v b=$SERIAL ' print a,b '
bash awk
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am trying to invoke awk inside a bash script and passing some bash variables values to it. Is there any way to get a count of these variables and print all which are passed to it inside awk.
No. of variables passed to awk would be dynamic.
Below example
#!/bin/bash
NAME="Dell"
SERIAL="12345"
echo "Hello" | awk -v a=$NAME -v b=$SERIAL ' print a,b '
bash awk
I am trying to invoke awk inside a bash script and passing some bash variables values to it. Is there any way to get a count of these variables and print all which are passed to it inside awk.
No. of variables passed to awk would be dynamic.
Below example
#!/bin/bash
NAME="Dell"
SERIAL="12345"
echo "Hello" | awk -v a=$NAME -v b=$SERIAL ' print a,b '
bash awk
bash awk
edited 3 mins ago
asked 23 mins ago
Bharat
3699
3699
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
One option I can think of is to reposition those variables so they feature in ARGV
. ARGC
will indicate how many of them there are. Beware this make the variables unavailable in BEGIN
block. You also need to account for any file names that you may be passing as parameters to awk
by subtracting the number of such files from ARGC
echo "Hello" | awk ' print a, b, ARGC - 1' a=$NAME b=$SERIAL
DELL 12345 2
ARGC should help, wondering why awk doesn't consider them as an input file
â Bharat
5 mins ago
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
One option I can think of is to reposition those variables so they feature in ARGV
. ARGC
will indicate how many of them there are. Beware this make the variables unavailable in BEGIN
block. You also need to account for any file names that you may be passing as parameters to awk
by subtracting the number of such files from ARGC
echo "Hello" | awk ' print a, b, ARGC - 1' a=$NAME b=$SERIAL
DELL 12345 2
ARGC should help, wondering why awk doesn't consider them as an input file
â Bharat
5 mins ago
add a comment |Â
up vote
1
down vote
accepted
One option I can think of is to reposition those variables so they feature in ARGV
. ARGC
will indicate how many of them there are. Beware this make the variables unavailable in BEGIN
block. You also need to account for any file names that you may be passing as parameters to awk
by subtracting the number of such files from ARGC
echo "Hello" | awk ' print a, b, ARGC - 1' a=$NAME b=$SERIAL
DELL 12345 2
ARGC should help, wondering why awk doesn't consider them as an input file
â Bharat
5 mins ago
add a comment |Â
up vote
1
down vote
accepted
up vote
1
down vote
accepted
One option I can think of is to reposition those variables so they feature in ARGV
. ARGC
will indicate how many of them there are. Beware this make the variables unavailable in BEGIN
block. You also need to account for any file names that you may be passing as parameters to awk
by subtracting the number of such files from ARGC
echo "Hello" | awk ' print a, b, ARGC - 1' a=$NAME b=$SERIAL
DELL 12345 2
One option I can think of is to reposition those variables so they feature in ARGV
. ARGC
will indicate how many of them there are. Beware this make the variables unavailable in BEGIN
block. You also need to account for any file names that you may be passing as parameters to awk
by subtracting the number of such files from ARGC
echo "Hello" | awk ' print a, b, ARGC - 1' a=$NAME b=$SERIAL
DELL 12345 2
edited 9 mins ago
answered 14 mins ago
iruvar
11.6k62959
11.6k62959
ARGC should help, wondering why awk doesn't consider them as an input file
â Bharat
5 mins ago
add a comment |Â
ARGC should help, wondering why awk doesn't consider them as an input file
â Bharat
5 mins ago
ARGC should help, wondering why awk doesn't consider them as an input file
â Bharat
5 mins ago
ARGC should help, wondering why awk doesn't consider them as an input file
â Bharat
5 mins ago
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%2f475201%2fhow-to-get-a-count-of-variables-passed-to-awk%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