parsing using loop and assigning row numbers to file
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
It is a bit complicated. i have a configuration file. it looks something like this.
customer="airtel"
model_name=fast
programmer_typ_of="dev"
Now the 1st column contains all the keys and whatever is after the =
is the value of each key. It is like this format:
key=value
How can I write a function where it will call such a file and store each key and value to two separate arrays where same position of each array will contain corresponding key and value. Please note that I cannot use the name of my key in the function anywhere neither I can grep using the exact key name. Alternatively I have thought of a way of solving this by assigning row numbers to the configuration file and the 'cut' each key and value pairs based on using grep
in a loop to find the individual row numbers. something like this :
function parse() grep ^$i
If you could tell me what is wrong in this function or if you could suggest some other method of getting separate key value pairs in different arrays.
linux shell-script centos c sparse-files
add a comment |
It is a bit complicated. i have a configuration file. it looks something like this.
customer="airtel"
model_name=fast
programmer_typ_of="dev"
Now the 1st column contains all the keys and whatever is after the =
is the value of each key. It is like this format:
key=value
How can I write a function where it will call such a file and store each key and value to two separate arrays where same position of each array will contain corresponding key and value. Please note that I cannot use the name of my key in the function anywhere neither I can grep using the exact key name. Alternatively I have thought of a way of solving this by assigning row numbers to the configuration file and the 'cut' each key and value pairs based on using grep
in a loop to find the individual row numbers. something like this :
function parse() grep ^$i
If you could tell me what is wrong in this function or if you could suggest some other method of getting separate key value pairs in different arrays.
linux shell-script centos c sparse-files
How many keys, and for what do you need to parse this? to feed other program? Only once, or many times? How often?
– Rui F Ribeiro
Jun 15 '16 at 9:34
@RuiFRibeiro : Thank you for your comment. there can be a number of keys but for each key there would be only one value. yes it would be needed to feed other program. it would be many times.
– Aditya Agarwal
Jun 15 '16 at 12:07
If it is very often, it would be more interesting using a key store engine like redis or memcached than using intermediate files.
– Rui F Ribeiro
Jun 15 '16 at 12:08
add a comment |
It is a bit complicated. i have a configuration file. it looks something like this.
customer="airtel"
model_name=fast
programmer_typ_of="dev"
Now the 1st column contains all the keys and whatever is after the =
is the value of each key. It is like this format:
key=value
How can I write a function where it will call such a file and store each key and value to two separate arrays where same position of each array will contain corresponding key and value. Please note that I cannot use the name of my key in the function anywhere neither I can grep using the exact key name. Alternatively I have thought of a way of solving this by assigning row numbers to the configuration file and the 'cut' each key and value pairs based on using grep
in a loop to find the individual row numbers. something like this :
function parse() grep ^$i
If you could tell me what is wrong in this function or if you could suggest some other method of getting separate key value pairs in different arrays.
linux shell-script centos c sparse-files
It is a bit complicated. i have a configuration file. it looks something like this.
customer="airtel"
model_name=fast
programmer_typ_of="dev"
Now the 1st column contains all the keys and whatever is after the =
is the value of each key. It is like this format:
key=value
How can I write a function where it will call such a file and store each key and value to two separate arrays where same position of each array will contain corresponding key and value. Please note that I cannot use the name of my key in the function anywhere neither I can grep using the exact key name. Alternatively I have thought of a way of solving this by assigning row numbers to the configuration file and the 'cut' each key and value pairs based on using grep
in a loop to find the individual row numbers. something like this :
function parse() grep ^$i
If you could tell me what is wrong in this function or if you could suggest some other method of getting separate key value pairs in different arrays.
linux shell-script centos c sparse-files
linux shell-script centos c sparse-files
edited Mar 9 at 14:06
Rui F Ribeiro
41.9k1483142
41.9k1483142
asked Jun 15 '16 at 8:36
Aditya AgarwalAditya Agarwal
35
35
How many keys, and for what do you need to parse this? to feed other program? Only once, or many times? How often?
– Rui F Ribeiro
Jun 15 '16 at 9:34
@RuiFRibeiro : Thank you for your comment. there can be a number of keys but for each key there would be only one value. yes it would be needed to feed other program. it would be many times.
– Aditya Agarwal
Jun 15 '16 at 12:07
If it is very often, it would be more interesting using a key store engine like redis or memcached than using intermediate files.
– Rui F Ribeiro
Jun 15 '16 at 12:08
add a comment |
How many keys, and for what do you need to parse this? to feed other program? Only once, or many times? How often?
– Rui F Ribeiro
Jun 15 '16 at 9:34
@RuiFRibeiro : Thank you for your comment. there can be a number of keys but for each key there would be only one value. yes it would be needed to feed other program. it would be many times.
– Aditya Agarwal
Jun 15 '16 at 12:07
If it is very often, it would be more interesting using a key store engine like redis or memcached than using intermediate files.
– Rui F Ribeiro
Jun 15 '16 at 12:08
How many keys, and for what do you need to parse this? to feed other program? Only once, or many times? How often?
– Rui F Ribeiro
Jun 15 '16 at 9:34
How many keys, and for what do you need to parse this? to feed other program? Only once, or many times? How often?
– Rui F Ribeiro
Jun 15 '16 at 9:34
@RuiFRibeiro : Thank you for your comment. there can be a number of keys but for each key there would be only one value. yes it would be needed to feed other program. it would be many times.
– Aditya Agarwal
Jun 15 '16 at 12:07
@RuiFRibeiro : Thank you for your comment. there can be a number of keys but for each key there would be only one value. yes it would be needed to feed other program. it would be many times.
– Aditya Agarwal
Jun 15 '16 at 12:07
If it is very often, it would be more interesting using a key store engine like redis or memcached than using intermediate files.
– Rui F Ribeiro
Jun 15 '16 at 12:08
If it is very often, it would be more interesting using a key store engine like redis or memcached than using intermediate files.
– Rui F Ribeiro
Jun 15 '16 at 12:08
add a comment |
2 Answers
2
active
oldest
votes
With awk:
eval $(awk -F= -v i=0 'print "arr1["i"]="$1";arr2["i"]="$2;i++' model.conf)
With =
as field seperator and variable i
with initial value 0
, awk
will print "arr1["i"]="$1";arr2["i"]="$2
for each line where $1
will have the key and $1
will have the value and increment i
for each line.
awk -F= -v i=0 'print "arr1["i"]="$1";arr2["i"]="$2;i++' model.conf
O/P:
arr1[0]=customer;arr2[0]="airtel"
arr1[1]=model_name;arr2[1]=fast
arr1[3]=programmer_typ_of;arr2[3]="dev"
Then use eval
on awk output to assign arrays.
thank you for your comment. as i am new to awk, could you kindly explain the command in details. could you also provide examples to explain if needed.
– Aditya Agarwal
Jun 15 '16 at 12:09
Edited the answer. I hope this will help.
– 7171u
Jun 15 '16 at 12:21
could you kindly explain this part arr1["i"]="$1" and arr2["i"]="$2. what is the function on $1 and $2, how is it taking each key and value everytime into account for each line. just not particularly clear about this. thank you.
– Aditya Agarwal
Jun 15 '16 at 13:14
awk reads files line by line. So for 1st linei
will be0
.i
incremtn by1
for each line.$1
and$2
are used to represent 1st and 2nd field.
– 7171u
Jun 15 '16 at 13:18
I recommend you readawk
basic tutorial to get more info.
– 7171u
Jun 15 '16 at 13:19
|
show 2 more comments
You can parse it directly using the bash shell's built-in read
function, by setting the field separator to =
while IFS== read -r name value; do
arr1+=("$name")
arr2+=("$value")
done < model.conf
The arrays will be zero indexed by default, i.e.
$ echo "$arr1[0]"
customer
$ echo "$arr2[0]"
"airtel"
Since variables (including arrays) have global scope unless explicitly declared as local
, you may put the parse loop in a function if you wish. To illustrate:
#!/bin/bash
function parse()
while IFS== read -r name value; do
arr1+=("$name")
arr2+=("$value")
done < model.conf
# call the function to extract key=value pairs from file to arrays
parse
# now we can use the arrays e.g.
for i in "$!arr1[@]"; do
printf 'key: %stvalue: %sn' "$arr1[$i]" "$arr2[$i]"
done
Result
key: customer value: "airtel"
key: model_name value: fast
key: programmer_typ_of value: "dev"
is there anyway i can declare these arrays globally and then call them in another function?
– Aditya Agarwal
Jun 16 '16 at 11:53
@AdityaAgarwal AFAIK bash variables have global scope unless explicitly declared aslocal
, so that should "just work"
– steeldriver
Jun 16 '16 at 12:36
could you kindly explain the above code with an example. it would actually help a lot.
– Aditya Agarwal
Jun 16 '16 at 12:58
@AdityaAgarwal please see edit
– steeldriver
Jun 16 '16 at 13:09
i am just being able to print the values of the two arrays in that format. i am not being able to use the value of the arrays in that function like passing a parameter in that function and then searching that value in both the arrays.
– Aditya Agarwal
Jun 16 '16 at 13:50
|
show 1 more comment
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
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
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f289857%2fparsing-using-loop-and-assigning-row-numbers-to-file%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
With awk:
eval $(awk -F= -v i=0 'print "arr1["i"]="$1";arr2["i"]="$2;i++' model.conf)
With =
as field seperator and variable i
with initial value 0
, awk
will print "arr1["i"]="$1";arr2["i"]="$2
for each line where $1
will have the key and $1
will have the value and increment i
for each line.
awk -F= -v i=0 'print "arr1["i"]="$1";arr2["i"]="$2;i++' model.conf
O/P:
arr1[0]=customer;arr2[0]="airtel"
arr1[1]=model_name;arr2[1]=fast
arr1[3]=programmer_typ_of;arr2[3]="dev"
Then use eval
on awk output to assign arrays.
thank you for your comment. as i am new to awk, could you kindly explain the command in details. could you also provide examples to explain if needed.
– Aditya Agarwal
Jun 15 '16 at 12:09
Edited the answer. I hope this will help.
– 7171u
Jun 15 '16 at 12:21
could you kindly explain this part arr1["i"]="$1" and arr2["i"]="$2. what is the function on $1 and $2, how is it taking each key and value everytime into account for each line. just not particularly clear about this. thank you.
– Aditya Agarwal
Jun 15 '16 at 13:14
awk reads files line by line. So for 1st linei
will be0
.i
incremtn by1
for each line.$1
and$2
are used to represent 1st and 2nd field.
– 7171u
Jun 15 '16 at 13:18
I recommend you readawk
basic tutorial to get more info.
– 7171u
Jun 15 '16 at 13:19
|
show 2 more comments
With awk:
eval $(awk -F= -v i=0 'print "arr1["i"]="$1";arr2["i"]="$2;i++' model.conf)
With =
as field seperator and variable i
with initial value 0
, awk
will print "arr1["i"]="$1";arr2["i"]="$2
for each line where $1
will have the key and $1
will have the value and increment i
for each line.
awk -F= -v i=0 'print "arr1["i"]="$1";arr2["i"]="$2;i++' model.conf
O/P:
arr1[0]=customer;arr2[0]="airtel"
arr1[1]=model_name;arr2[1]=fast
arr1[3]=programmer_typ_of;arr2[3]="dev"
Then use eval
on awk output to assign arrays.
thank you for your comment. as i am new to awk, could you kindly explain the command in details. could you also provide examples to explain if needed.
– Aditya Agarwal
Jun 15 '16 at 12:09
Edited the answer. I hope this will help.
– 7171u
Jun 15 '16 at 12:21
could you kindly explain this part arr1["i"]="$1" and arr2["i"]="$2. what is the function on $1 and $2, how is it taking each key and value everytime into account for each line. just not particularly clear about this. thank you.
– Aditya Agarwal
Jun 15 '16 at 13:14
awk reads files line by line. So for 1st linei
will be0
.i
incremtn by1
for each line.$1
and$2
are used to represent 1st and 2nd field.
– 7171u
Jun 15 '16 at 13:18
I recommend you readawk
basic tutorial to get more info.
– 7171u
Jun 15 '16 at 13:19
|
show 2 more comments
With awk:
eval $(awk -F= -v i=0 'print "arr1["i"]="$1";arr2["i"]="$2;i++' model.conf)
With =
as field seperator and variable i
with initial value 0
, awk
will print "arr1["i"]="$1";arr2["i"]="$2
for each line where $1
will have the key and $1
will have the value and increment i
for each line.
awk -F= -v i=0 'print "arr1["i"]="$1";arr2["i"]="$2;i++' model.conf
O/P:
arr1[0]=customer;arr2[0]="airtel"
arr1[1]=model_name;arr2[1]=fast
arr1[3]=programmer_typ_of;arr2[3]="dev"
Then use eval
on awk output to assign arrays.
With awk:
eval $(awk -F= -v i=0 'print "arr1["i"]="$1";arr2["i"]="$2;i++' model.conf)
With =
as field seperator and variable i
with initial value 0
, awk
will print "arr1["i"]="$1";arr2["i"]="$2
for each line where $1
will have the key and $1
will have the value and increment i
for each line.
awk -F= -v i=0 'print "arr1["i"]="$1";arr2["i"]="$2;i++' model.conf
O/P:
arr1[0]=customer;arr2[0]="airtel"
arr1[1]=model_name;arr2[1]=fast
arr1[3]=programmer_typ_of;arr2[3]="dev"
Then use eval
on awk output to assign arrays.
edited Jun 15 '16 at 12:21
answered Jun 15 '16 at 9:45
7171u7171u
88549
88549
thank you for your comment. as i am new to awk, could you kindly explain the command in details. could you also provide examples to explain if needed.
– Aditya Agarwal
Jun 15 '16 at 12:09
Edited the answer. I hope this will help.
– 7171u
Jun 15 '16 at 12:21
could you kindly explain this part arr1["i"]="$1" and arr2["i"]="$2. what is the function on $1 and $2, how is it taking each key and value everytime into account for each line. just not particularly clear about this. thank you.
– Aditya Agarwal
Jun 15 '16 at 13:14
awk reads files line by line. So for 1st linei
will be0
.i
incremtn by1
for each line.$1
and$2
are used to represent 1st and 2nd field.
– 7171u
Jun 15 '16 at 13:18
I recommend you readawk
basic tutorial to get more info.
– 7171u
Jun 15 '16 at 13:19
|
show 2 more comments
thank you for your comment. as i am new to awk, could you kindly explain the command in details. could you also provide examples to explain if needed.
– Aditya Agarwal
Jun 15 '16 at 12:09
Edited the answer. I hope this will help.
– 7171u
Jun 15 '16 at 12:21
could you kindly explain this part arr1["i"]="$1" and arr2["i"]="$2. what is the function on $1 and $2, how is it taking each key and value everytime into account for each line. just not particularly clear about this. thank you.
– Aditya Agarwal
Jun 15 '16 at 13:14
awk reads files line by line. So for 1st linei
will be0
.i
incremtn by1
for each line.$1
and$2
are used to represent 1st and 2nd field.
– 7171u
Jun 15 '16 at 13:18
I recommend you readawk
basic tutorial to get more info.
– 7171u
Jun 15 '16 at 13:19
thank you for your comment. as i am new to awk, could you kindly explain the command in details. could you also provide examples to explain if needed.
– Aditya Agarwal
Jun 15 '16 at 12:09
thank you for your comment. as i am new to awk, could you kindly explain the command in details. could you also provide examples to explain if needed.
– Aditya Agarwal
Jun 15 '16 at 12:09
Edited the answer. I hope this will help.
– 7171u
Jun 15 '16 at 12:21
Edited the answer. I hope this will help.
– 7171u
Jun 15 '16 at 12:21
could you kindly explain this part arr1["i"]="$1" and arr2["i"]="$2. what is the function on $1 and $2, how is it taking each key and value everytime into account for each line. just not particularly clear about this. thank you.
– Aditya Agarwal
Jun 15 '16 at 13:14
could you kindly explain this part arr1["i"]="$1" and arr2["i"]="$2. what is the function on $1 and $2, how is it taking each key and value everytime into account for each line. just not particularly clear about this. thank you.
– Aditya Agarwal
Jun 15 '16 at 13:14
awk reads files line by line. So for 1st line
i
will be 0
. i
incremtn by 1
for each line. $1
and $2
are used to represent 1st and 2nd field.– 7171u
Jun 15 '16 at 13:18
awk reads files line by line. So for 1st line
i
will be 0
. i
incremtn by 1
for each line. $1
and $2
are used to represent 1st and 2nd field.– 7171u
Jun 15 '16 at 13:18
I recommend you read
awk
basic tutorial to get more info.– 7171u
Jun 15 '16 at 13:19
I recommend you read
awk
basic tutorial to get more info.– 7171u
Jun 15 '16 at 13:19
|
show 2 more comments
You can parse it directly using the bash shell's built-in read
function, by setting the field separator to =
while IFS== read -r name value; do
arr1+=("$name")
arr2+=("$value")
done < model.conf
The arrays will be zero indexed by default, i.e.
$ echo "$arr1[0]"
customer
$ echo "$arr2[0]"
"airtel"
Since variables (including arrays) have global scope unless explicitly declared as local
, you may put the parse loop in a function if you wish. To illustrate:
#!/bin/bash
function parse()
while IFS== read -r name value; do
arr1+=("$name")
arr2+=("$value")
done < model.conf
# call the function to extract key=value pairs from file to arrays
parse
# now we can use the arrays e.g.
for i in "$!arr1[@]"; do
printf 'key: %stvalue: %sn' "$arr1[$i]" "$arr2[$i]"
done
Result
key: customer value: "airtel"
key: model_name value: fast
key: programmer_typ_of value: "dev"
is there anyway i can declare these arrays globally and then call them in another function?
– Aditya Agarwal
Jun 16 '16 at 11:53
@AdityaAgarwal AFAIK bash variables have global scope unless explicitly declared aslocal
, so that should "just work"
– steeldriver
Jun 16 '16 at 12:36
could you kindly explain the above code with an example. it would actually help a lot.
– Aditya Agarwal
Jun 16 '16 at 12:58
@AdityaAgarwal please see edit
– steeldriver
Jun 16 '16 at 13:09
i am just being able to print the values of the two arrays in that format. i am not being able to use the value of the arrays in that function like passing a parameter in that function and then searching that value in both the arrays.
– Aditya Agarwal
Jun 16 '16 at 13:50
|
show 1 more comment
You can parse it directly using the bash shell's built-in read
function, by setting the field separator to =
while IFS== read -r name value; do
arr1+=("$name")
arr2+=("$value")
done < model.conf
The arrays will be zero indexed by default, i.e.
$ echo "$arr1[0]"
customer
$ echo "$arr2[0]"
"airtel"
Since variables (including arrays) have global scope unless explicitly declared as local
, you may put the parse loop in a function if you wish. To illustrate:
#!/bin/bash
function parse()
while IFS== read -r name value; do
arr1+=("$name")
arr2+=("$value")
done < model.conf
# call the function to extract key=value pairs from file to arrays
parse
# now we can use the arrays e.g.
for i in "$!arr1[@]"; do
printf 'key: %stvalue: %sn' "$arr1[$i]" "$arr2[$i]"
done
Result
key: customer value: "airtel"
key: model_name value: fast
key: programmer_typ_of value: "dev"
is there anyway i can declare these arrays globally and then call them in another function?
– Aditya Agarwal
Jun 16 '16 at 11:53
@AdityaAgarwal AFAIK bash variables have global scope unless explicitly declared aslocal
, so that should "just work"
– steeldriver
Jun 16 '16 at 12:36
could you kindly explain the above code with an example. it would actually help a lot.
– Aditya Agarwal
Jun 16 '16 at 12:58
@AdityaAgarwal please see edit
– steeldriver
Jun 16 '16 at 13:09
i am just being able to print the values of the two arrays in that format. i am not being able to use the value of the arrays in that function like passing a parameter in that function and then searching that value in both the arrays.
– Aditya Agarwal
Jun 16 '16 at 13:50
|
show 1 more comment
You can parse it directly using the bash shell's built-in read
function, by setting the field separator to =
while IFS== read -r name value; do
arr1+=("$name")
arr2+=("$value")
done < model.conf
The arrays will be zero indexed by default, i.e.
$ echo "$arr1[0]"
customer
$ echo "$arr2[0]"
"airtel"
Since variables (including arrays) have global scope unless explicitly declared as local
, you may put the parse loop in a function if you wish. To illustrate:
#!/bin/bash
function parse()
while IFS== read -r name value; do
arr1+=("$name")
arr2+=("$value")
done < model.conf
# call the function to extract key=value pairs from file to arrays
parse
# now we can use the arrays e.g.
for i in "$!arr1[@]"; do
printf 'key: %stvalue: %sn' "$arr1[$i]" "$arr2[$i]"
done
Result
key: customer value: "airtel"
key: model_name value: fast
key: programmer_typ_of value: "dev"
You can parse it directly using the bash shell's built-in read
function, by setting the field separator to =
while IFS== read -r name value; do
arr1+=("$name")
arr2+=("$value")
done < model.conf
The arrays will be zero indexed by default, i.e.
$ echo "$arr1[0]"
customer
$ echo "$arr2[0]"
"airtel"
Since variables (including arrays) have global scope unless explicitly declared as local
, you may put the parse loop in a function if you wish. To illustrate:
#!/bin/bash
function parse()
while IFS== read -r name value; do
arr1+=("$name")
arr2+=("$value")
done < model.conf
# call the function to extract key=value pairs from file to arrays
parse
# now we can use the arrays e.g.
for i in "$!arr1[@]"; do
printf 'key: %stvalue: %sn' "$arr1[$i]" "$arr2[$i]"
done
Result
key: customer value: "airtel"
key: model_name value: fast
key: programmer_typ_of value: "dev"
edited Jun 16 '16 at 13:08
answered Jun 15 '16 at 12:06
steeldriversteeldriver
37.7k45389
37.7k45389
is there anyway i can declare these arrays globally and then call them in another function?
– Aditya Agarwal
Jun 16 '16 at 11:53
@AdityaAgarwal AFAIK bash variables have global scope unless explicitly declared aslocal
, so that should "just work"
– steeldriver
Jun 16 '16 at 12:36
could you kindly explain the above code with an example. it would actually help a lot.
– Aditya Agarwal
Jun 16 '16 at 12:58
@AdityaAgarwal please see edit
– steeldriver
Jun 16 '16 at 13:09
i am just being able to print the values of the two arrays in that format. i am not being able to use the value of the arrays in that function like passing a parameter in that function and then searching that value in both the arrays.
– Aditya Agarwal
Jun 16 '16 at 13:50
|
show 1 more comment
is there anyway i can declare these arrays globally and then call them in another function?
– Aditya Agarwal
Jun 16 '16 at 11:53
@AdityaAgarwal AFAIK bash variables have global scope unless explicitly declared aslocal
, so that should "just work"
– steeldriver
Jun 16 '16 at 12:36
could you kindly explain the above code with an example. it would actually help a lot.
– Aditya Agarwal
Jun 16 '16 at 12:58
@AdityaAgarwal please see edit
– steeldriver
Jun 16 '16 at 13:09
i am just being able to print the values of the two arrays in that format. i am not being able to use the value of the arrays in that function like passing a parameter in that function and then searching that value in both the arrays.
– Aditya Agarwal
Jun 16 '16 at 13:50
is there anyway i can declare these arrays globally and then call them in another function?
– Aditya Agarwal
Jun 16 '16 at 11:53
is there anyway i can declare these arrays globally and then call them in another function?
– Aditya Agarwal
Jun 16 '16 at 11:53
@AdityaAgarwal AFAIK bash variables have global scope unless explicitly declared as
local
, so that should "just work"– steeldriver
Jun 16 '16 at 12:36
@AdityaAgarwal AFAIK bash variables have global scope unless explicitly declared as
local
, so that should "just work"– steeldriver
Jun 16 '16 at 12:36
could you kindly explain the above code with an example. it would actually help a lot.
– Aditya Agarwal
Jun 16 '16 at 12:58
could you kindly explain the above code with an example. it would actually help a lot.
– Aditya Agarwal
Jun 16 '16 at 12:58
@AdityaAgarwal please see edit
– steeldriver
Jun 16 '16 at 13:09
@AdityaAgarwal please see edit
– steeldriver
Jun 16 '16 at 13:09
i am just being able to print the values of the two arrays in that format. i am not being able to use the value of the arrays in that function like passing a parameter in that function and then searching that value in both the arrays.
– Aditya Agarwal
Jun 16 '16 at 13:50
i am just being able to print the values of the two arrays in that format. i am not being able to use the value of the arrays in that function like passing a parameter in that function and then searching that value in both the arrays.
– Aditya Agarwal
Jun 16 '16 at 13:50
|
show 1 more comment
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f289857%2fparsing-using-loop-and-assigning-row-numbers-to-file%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
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
Required, but never shown
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
Required, but never shown
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
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
How many keys, and for what do you need to parse this? to feed other program? Only once, or many times? How often?
– Rui F Ribeiro
Jun 15 '16 at 9:34
@RuiFRibeiro : Thank you for your comment. there can be a number of keys but for each key there would be only one value. yes it would be needed to feed other program. it would be many times.
– Aditya Agarwal
Jun 15 '16 at 12:07
If it is very often, it would be more interesting using a key store engine like redis or memcached than using intermediate files.
– Rui F Ribeiro
Jun 15 '16 at 12:08