How can use the loop variable to create an array with the current iteration in AWKvlookup function in unixHow to interpret busybox “top” output?Exchanging One Column From File1 with files from File2Processing table with comma separated values in different columnsComparing across rows in PerlPrint if for the same 1st field there's a single value of 2nd field on all linesArithmetic calculation row-wise for non-fixed column numberHow to find lines with different values in 5th column which share the same 2nd column?Calculate interval if value in column changesUsing Awk to print desired lines of nslookup
Short story about an infectious indestructible metal bar?
How to recover against Snake as a heavyweight character?
Generating a list with duplicate entries
I am the person who abides by rules but breaks the rules . Who am I
Should I file my taxes? No income, unemployed, but paid 2k in student loan interest
Professor forcing me to attend a conference, I can't afford even with 50% funding
Is it appropriate to ask a former professor to order a library book for me through ILL?
Rationale to prefer local variables over instance variables?
Limpar string com Regex
Is there a logarithm base for which the logarithm becomes an identity function?
Is it a Cyclops number? "Nobody" knows!
Was this cameo in Captain Marvel computer generated?
Can multiple states demand income tax from an LLC?
I am the light that shines in the dark
Paper published similar to PhD thesis
How to install "rounded" brake pads
PTIJ: Sport in the Torah
Can Witch Sight see through Mirror Image?
How does a sound wave propagate?
How would an energy-based "projectile" blow up a spaceship?
How to educate team mate to take screenshots for bugs with out unwanted stuff
How do you make a gun that shoots melee weapons and/or swords?
What does *dead* mean in *What do you mean, dead?*?
Ultrafilters as a double dual
How can use the loop variable to create an array with the current iteration in AWK
vlookup function in unixHow to interpret busybox “top” output?Exchanging One Column From File1 with files from File2Processing table with comma separated values in different columnsComparing across rows in PerlPrint if for the same 1st field there's a single value of 2nd field on all linesArithmetic calculation row-wise for non-fixed column numberHow to find lines with different values in 5th column which share the same 2nd column?Calculate interval if value in column changesUsing Awk to print desired lines of nslookup
I'm trying to store all the values into variables so I can use them later, I've found and example which is useful, but in the example only has 3 columns, and the files that I'm working on have a lot more, this is the code:
#!/usr/bin/awk -f
array1[NR]=$3;array2[NR]=$4;array3[NR]=$5
END
for(i=1;i<=NR;i++)
print "Column"i" "array1[i]
for(i=1;i<=NR;i++)
print "Column"i" "array2[i]
for(i=1;i<=NR;i++)
print "Column"i" "array3[i]
That I want to do is, first to iterate trough all the columns and store them in an array starting from column number 3, because column 1 and 2 are the date.
Second, then I want to work to iterate through everything to print a new line with every value on the array. something like this:
BEGIN
for(i=1;i<=NR;i++)
for(j=1;j<=NR;j++)
array$i<--arrayname based con the for variable[NR]=$j<---column number based on the for variable
I wasn't able to use the FOR variables to create the array name, so I get an error.
After that I want to do the second part in the example but using the same logic, I iterate through every thing to create new lines.
Appreciate your help.
EDIT: I'm trying to use the 3 value of the second record which is the CPU User%
#Date Time [CPU]User% [CPU]Nice% [CPU]Sys% [CPU]Wait% [CPU]Irq% [CPU]Soft% [CPU]Steal% [CPU]Idle% [CPU]Totl% [CPU]Intrpt/sec [CPU]Ctx/sec [CPU]Proc/sec [CPU]ProcQue [CPU]ProcRun [CPU]L-Avg1 [CPU]L-Avg5 [CPU]L-Avg15
20190228 00:01:00 12 0 3 0 0 1 0 84 16 26957 20219 14 2991 3 0.05 0.18 0.13
20190228 00:02:00 11 0 3 0 0 1 0 85 15 26062 18226 5 2988 3 0.02 0.14 0.12
20190228 00:03:00 11 0 3 0 0 1 0 85 15 25750 17963 4 2980 0 0.00 0.11 0.10
20190228 00:04:00 11 0 3 0 0 1 0 84 16 25755 17871 10 2981 5 0.08 0.11 0.10
20190228 00:05:00 12 0 4 0 0 1 0 83 17 26243 18319 76 2985 3 0.06 0.10 0.09
20190228 00:06:00 11 0 3 0 0 1 0 84 16 26135 18229 21 2977 1 0.02 0.08 0.09
20190228 00:07:00 12 0 3 0 0 1 0 84 16 26112 18238 10 2983 2 0.01 0.06 0.08
Expected output is like this one
cpu_value,host=mxspacr1,type=cpu,type_instance=[CPU]User% value=5542875 1551128614916066891
cpu_value,host=mxspacr1,type=cpu,type_instance=[CPU]Nice% value=5477864 1551128614916078438
cpu_value,host=mxspacr1,type=cpu,type_instance=[CPU]Sys% value=6515452 1551128614916063122
cpu_value,host=mxspacr1,type=cpu,type_instance=[CPU]Wait% value=11349674 1551128614916076302
cpu_value,host=mxspacr1,type=cpu,type_instance=[CPU]Irq% value=11349674 1551128614916076302
cpu_value,host=mxspacr1,type=cpu,type_instance=[CPU]Soft% value=11349674 1551128614916076302
cpu_value,host=mxspacr1,type=cpu,type_instance=[CPU]Steal% value=11349674 1551128614916076302
cpu_value,host=mxspacr1,type=cpu,type_instance=[CPU]Idle% value=5542875 1551128614916066891
The reason I'm splitting the file and extracting only the CPU parameters is because I will hardcode "cpu_value" and "type=cpu", the type_instance I will extract it from the first row.
linux text-processing awk
|
show 10 more comments
I'm trying to store all the values into variables so I can use them later, I've found and example which is useful, but in the example only has 3 columns, and the files that I'm working on have a lot more, this is the code:
#!/usr/bin/awk -f
array1[NR]=$3;array2[NR]=$4;array3[NR]=$5
END
for(i=1;i<=NR;i++)
print "Column"i" "array1[i]
for(i=1;i<=NR;i++)
print "Column"i" "array2[i]
for(i=1;i<=NR;i++)
print "Column"i" "array3[i]
That I want to do is, first to iterate trough all the columns and store them in an array starting from column number 3, because column 1 and 2 are the date.
Second, then I want to work to iterate through everything to print a new line with every value on the array. something like this:
BEGIN
for(i=1;i<=NR;i++)
for(j=1;j<=NR;j++)
array$i<--arrayname based con the for variable[NR]=$j<---column number based on the for variable
I wasn't able to use the FOR variables to create the array name, so I get an error.
After that I want to do the second part in the example but using the same logic, I iterate through every thing to create new lines.
Appreciate your help.
EDIT: I'm trying to use the 3 value of the second record which is the CPU User%
#Date Time [CPU]User% [CPU]Nice% [CPU]Sys% [CPU]Wait% [CPU]Irq% [CPU]Soft% [CPU]Steal% [CPU]Idle% [CPU]Totl% [CPU]Intrpt/sec [CPU]Ctx/sec [CPU]Proc/sec [CPU]ProcQue [CPU]ProcRun [CPU]L-Avg1 [CPU]L-Avg5 [CPU]L-Avg15
20190228 00:01:00 12 0 3 0 0 1 0 84 16 26957 20219 14 2991 3 0.05 0.18 0.13
20190228 00:02:00 11 0 3 0 0 1 0 85 15 26062 18226 5 2988 3 0.02 0.14 0.12
20190228 00:03:00 11 0 3 0 0 1 0 85 15 25750 17963 4 2980 0 0.00 0.11 0.10
20190228 00:04:00 11 0 3 0 0 1 0 84 16 25755 17871 10 2981 5 0.08 0.11 0.10
20190228 00:05:00 12 0 4 0 0 1 0 83 17 26243 18319 76 2985 3 0.06 0.10 0.09
20190228 00:06:00 11 0 3 0 0 1 0 84 16 26135 18229 21 2977 1 0.02 0.08 0.09
20190228 00:07:00 12 0 3 0 0 1 0 84 16 26112 18238 10 2983 2 0.01 0.06 0.08
Expected output is like this one
cpu_value,host=mxspacr1,type=cpu,type_instance=[CPU]User% value=5542875 1551128614916066891
cpu_value,host=mxspacr1,type=cpu,type_instance=[CPU]Nice% value=5477864 1551128614916078438
cpu_value,host=mxspacr1,type=cpu,type_instance=[CPU]Sys% value=6515452 1551128614916063122
cpu_value,host=mxspacr1,type=cpu,type_instance=[CPU]Wait% value=11349674 1551128614916076302
cpu_value,host=mxspacr1,type=cpu,type_instance=[CPU]Irq% value=11349674 1551128614916076302
cpu_value,host=mxspacr1,type=cpu,type_instance=[CPU]Soft% value=11349674 1551128614916076302
cpu_value,host=mxspacr1,type=cpu,type_instance=[CPU]Steal% value=11349674 1551128614916076302
cpu_value,host=mxspacr1,type=cpu,type_instance=[CPU]Idle% value=5542875 1551128614916066891
The reason I'm splitting the file and extracting only the CPU parameters is because I will hardcode "cpu_value" and "type=cpu", the type_instance I will extract it from the first row.
linux text-processing awk
It's not clear to me what you expect to happen here:NR
is the record (line) number - if you want to loop over columns (fields) the variable you need to refer to in your loop isNF
; in any case, both will be zero inside aBEGIN
block
– steeldriver
5 hours ago
Do you have an example where you actually need to store all the files data before processing it from your arrays in theEND
block? What's stopping you from just storing$0
from each line and then usingsplit()
on these later in that case?
– Kusalananda
5 hours ago
Hello, ok I think that what is doing for example the first array1[NR]=$3 is storing into record all the information from column 3, which is what I want, the thing is that I have 139 columns so I don't want to declare every array manually. That is what I want to create all 139 arrays using a for loop and using the current value of iteration, for example when i=1 create an array called array1, and so on.
– Eduardo Santiago López
4 hours ago
1
At least if you have a fairly recent version of GNU awk, you can use Arrays of Arrays
– steeldriver
4 hours ago
1
You have 7 lines of input that produces about 14 lines of output. The values forvalue
don't make sense. I'm utterly confused. Are the last column timestamps? They are out of range. In any case, you don't need arrays for this.
– Kusalananda
3 hours ago
|
show 10 more comments
I'm trying to store all the values into variables so I can use them later, I've found and example which is useful, but in the example only has 3 columns, and the files that I'm working on have a lot more, this is the code:
#!/usr/bin/awk -f
array1[NR]=$3;array2[NR]=$4;array3[NR]=$5
END
for(i=1;i<=NR;i++)
print "Column"i" "array1[i]
for(i=1;i<=NR;i++)
print "Column"i" "array2[i]
for(i=1;i<=NR;i++)
print "Column"i" "array3[i]
That I want to do is, first to iterate trough all the columns and store them in an array starting from column number 3, because column 1 and 2 are the date.
Second, then I want to work to iterate through everything to print a new line with every value on the array. something like this:
BEGIN
for(i=1;i<=NR;i++)
for(j=1;j<=NR;j++)
array$i<--arrayname based con the for variable[NR]=$j<---column number based on the for variable
I wasn't able to use the FOR variables to create the array name, so I get an error.
After that I want to do the second part in the example but using the same logic, I iterate through every thing to create new lines.
Appreciate your help.
EDIT: I'm trying to use the 3 value of the second record which is the CPU User%
#Date Time [CPU]User% [CPU]Nice% [CPU]Sys% [CPU]Wait% [CPU]Irq% [CPU]Soft% [CPU]Steal% [CPU]Idle% [CPU]Totl% [CPU]Intrpt/sec [CPU]Ctx/sec [CPU]Proc/sec [CPU]ProcQue [CPU]ProcRun [CPU]L-Avg1 [CPU]L-Avg5 [CPU]L-Avg15
20190228 00:01:00 12 0 3 0 0 1 0 84 16 26957 20219 14 2991 3 0.05 0.18 0.13
20190228 00:02:00 11 0 3 0 0 1 0 85 15 26062 18226 5 2988 3 0.02 0.14 0.12
20190228 00:03:00 11 0 3 0 0 1 0 85 15 25750 17963 4 2980 0 0.00 0.11 0.10
20190228 00:04:00 11 0 3 0 0 1 0 84 16 25755 17871 10 2981 5 0.08 0.11 0.10
20190228 00:05:00 12 0 4 0 0 1 0 83 17 26243 18319 76 2985 3 0.06 0.10 0.09
20190228 00:06:00 11 0 3 0 0 1 0 84 16 26135 18229 21 2977 1 0.02 0.08 0.09
20190228 00:07:00 12 0 3 0 0 1 0 84 16 26112 18238 10 2983 2 0.01 0.06 0.08
Expected output is like this one
cpu_value,host=mxspacr1,type=cpu,type_instance=[CPU]User% value=5542875 1551128614916066891
cpu_value,host=mxspacr1,type=cpu,type_instance=[CPU]Nice% value=5477864 1551128614916078438
cpu_value,host=mxspacr1,type=cpu,type_instance=[CPU]Sys% value=6515452 1551128614916063122
cpu_value,host=mxspacr1,type=cpu,type_instance=[CPU]Wait% value=11349674 1551128614916076302
cpu_value,host=mxspacr1,type=cpu,type_instance=[CPU]Irq% value=11349674 1551128614916076302
cpu_value,host=mxspacr1,type=cpu,type_instance=[CPU]Soft% value=11349674 1551128614916076302
cpu_value,host=mxspacr1,type=cpu,type_instance=[CPU]Steal% value=11349674 1551128614916076302
cpu_value,host=mxspacr1,type=cpu,type_instance=[CPU]Idle% value=5542875 1551128614916066891
The reason I'm splitting the file and extracting only the CPU parameters is because I will hardcode "cpu_value" and "type=cpu", the type_instance I will extract it from the first row.
linux text-processing awk
I'm trying to store all the values into variables so I can use them later, I've found and example which is useful, but in the example only has 3 columns, and the files that I'm working on have a lot more, this is the code:
#!/usr/bin/awk -f
array1[NR]=$3;array2[NR]=$4;array3[NR]=$5
END
for(i=1;i<=NR;i++)
print "Column"i" "array1[i]
for(i=1;i<=NR;i++)
print "Column"i" "array2[i]
for(i=1;i<=NR;i++)
print "Column"i" "array3[i]
That I want to do is, first to iterate trough all the columns and store them in an array starting from column number 3, because column 1 and 2 are the date.
Second, then I want to work to iterate through everything to print a new line with every value on the array. something like this:
BEGIN
for(i=1;i<=NR;i++)
for(j=1;j<=NR;j++)
array$i<--arrayname based con the for variable[NR]=$j<---column number based on the for variable
I wasn't able to use the FOR variables to create the array name, so I get an error.
After that I want to do the second part in the example but using the same logic, I iterate through every thing to create new lines.
Appreciate your help.
EDIT: I'm trying to use the 3 value of the second record which is the CPU User%
#Date Time [CPU]User% [CPU]Nice% [CPU]Sys% [CPU]Wait% [CPU]Irq% [CPU]Soft% [CPU]Steal% [CPU]Idle% [CPU]Totl% [CPU]Intrpt/sec [CPU]Ctx/sec [CPU]Proc/sec [CPU]ProcQue [CPU]ProcRun [CPU]L-Avg1 [CPU]L-Avg5 [CPU]L-Avg15
20190228 00:01:00 12 0 3 0 0 1 0 84 16 26957 20219 14 2991 3 0.05 0.18 0.13
20190228 00:02:00 11 0 3 0 0 1 0 85 15 26062 18226 5 2988 3 0.02 0.14 0.12
20190228 00:03:00 11 0 3 0 0 1 0 85 15 25750 17963 4 2980 0 0.00 0.11 0.10
20190228 00:04:00 11 0 3 0 0 1 0 84 16 25755 17871 10 2981 5 0.08 0.11 0.10
20190228 00:05:00 12 0 4 0 0 1 0 83 17 26243 18319 76 2985 3 0.06 0.10 0.09
20190228 00:06:00 11 0 3 0 0 1 0 84 16 26135 18229 21 2977 1 0.02 0.08 0.09
20190228 00:07:00 12 0 3 0 0 1 0 84 16 26112 18238 10 2983 2 0.01 0.06 0.08
Expected output is like this one
cpu_value,host=mxspacr1,type=cpu,type_instance=[CPU]User% value=5542875 1551128614916066891
cpu_value,host=mxspacr1,type=cpu,type_instance=[CPU]Nice% value=5477864 1551128614916078438
cpu_value,host=mxspacr1,type=cpu,type_instance=[CPU]Sys% value=6515452 1551128614916063122
cpu_value,host=mxspacr1,type=cpu,type_instance=[CPU]Wait% value=11349674 1551128614916076302
cpu_value,host=mxspacr1,type=cpu,type_instance=[CPU]Irq% value=11349674 1551128614916076302
cpu_value,host=mxspacr1,type=cpu,type_instance=[CPU]Soft% value=11349674 1551128614916076302
cpu_value,host=mxspacr1,type=cpu,type_instance=[CPU]Steal% value=11349674 1551128614916076302
cpu_value,host=mxspacr1,type=cpu,type_instance=[CPU]Idle% value=5542875 1551128614916066891
The reason I'm splitting the file and extracting only the CPU parameters is because I will hardcode "cpu_value" and "type=cpu", the type_instance I will extract it from the first row.
linux text-processing awk
linux text-processing awk
edited 3 hours ago
Eduardo Santiago López
asked 5 hours ago
Eduardo Santiago LópezEduardo Santiago López
34
34
It's not clear to me what you expect to happen here:NR
is the record (line) number - if you want to loop over columns (fields) the variable you need to refer to in your loop isNF
; in any case, both will be zero inside aBEGIN
block
– steeldriver
5 hours ago
Do you have an example where you actually need to store all the files data before processing it from your arrays in theEND
block? What's stopping you from just storing$0
from each line and then usingsplit()
on these later in that case?
– Kusalananda
5 hours ago
Hello, ok I think that what is doing for example the first array1[NR]=$3 is storing into record all the information from column 3, which is what I want, the thing is that I have 139 columns so I don't want to declare every array manually. That is what I want to create all 139 arrays using a for loop and using the current value of iteration, for example when i=1 create an array called array1, and so on.
– Eduardo Santiago López
4 hours ago
1
At least if you have a fairly recent version of GNU awk, you can use Arrays of Arrays
– steeldriver
4 hours ago
1
You have 7 lines of input that produces about 14 lines of output. The values forvalue
don't make sense. I'm utterly confused. Are the last column timestamps? They are out of range. In any case, you don't need arrays for this.
– Kusalananda
3 hours ago
|
show 10 more comments
It's not clear to me what you expect to happen here:NR
is the record (line) number - if you want to loop over columns (fields) the variable you need to refer to in your loop isNF
; in any case, both will be zero inside aBEGIN
block
– steeldriver
5 hours ago
Do you have an example where you actually need to store all the files data before processing it from your arrays in theEND
block? What's stopping you from just storing$0
from each line and then usingsplit()
on these later in that case?
– Kusalananda
5 hours ago
Hello, ok I think that what is doing for example the first array1[NR]=$3 is storing into record all the information from column 3, which is what I want, the thing is that I have 139 columns so I don't want to declare every array manually. That is what I want to create all 139 arrays using a for loop and using the current value of iteration, for example when i=1 create an array called array1, and so on.
– Eduardo Santiago López
4 hours ago
1
At least if you have a fairly recent version of GNU awk, you can use Arrays of Arrays
– steeldriver
4 hours ago
1
You have 7 lines of input that produces about 14 lines of output. The values forvalue
don't make sense. I'm utterly confused. Are the last column timestamps? They are out of range. In any case, you don't need arrays for this.
– Kusalananda
3 hours ago
It's not clear to me what you expect to happen here:
NR
is the record (line) number - if you want to loop over columns (fields) the variable you need to refer to in your loop is NF
; in any case, both will be zero inside a BEGIN
block– steeldriver
5 hours ago
It's not clear to me what you expect to happen here:
NR
is the record (line) number - if you want to loop over columns (fields) the variable you need to refer to in your loop is NF
; in any case, both will be zero inside a BEGIN
block– steeldriver
5 hours ago
Do you have an example where you actually need to store all the files data before processing it from your arrays in the
END
block? What's stopping you from just storing $0
from each line and then using split()
on these later in that case?– Kusalananda
5 hours ago
Do you have an example where you actually need to store all the files data before processing it from your arrays in the
END
block? What's stopping you from just storing $0
from each line and then using split()
on these later in that case?– Kusalananda
5 hours ago
Hello, ok I think that what is doing for example the first array1[NR]=$3 is storing into record all the information from column 3, which is what I want, the thing is that I have 139 columns so I don't want to declare every array manually. That is what I want to create all 139 arrays using a for loop and using the current value of iteration, for example when i=1 create an array called array1, and so on.
– Eduardo Santiago López
4 hours ago
Hello, ok I think that what is doing for example the first array1[NR]=$3 is storing into record all the information from column 3, which is what I want, the thing is that I have 139 columns so I don't want to declare every array manually. That is what I want to create all 139 arrays using a for loop and using the current value of iteration, for example when i=1 create an array called array1, and so on.
– Eduardo Santiago López
4 hours ago
1
1
At least if you have a fairly recent version of GNU awk, you can use Arrays of Arrays
– steeldriver
4 hours ago
At least if you have a fairly recent version of GNU awk, you can use Arrays of Arrays
– steeldriver
4 hours ago
1
1
You have 7 lines of input that produces about 14 lines of output. The values for
value
don't make sense. I'm utterly confused. Are the last column timestamps? They are out of range. In any case, you don't need arrays for this.– Kusalananda
3 hours ago
You have 7 lines of input that produces about 14 lines of output. The values for
value
don't make sense. I'm utterly confused. Are the last column timestamps? They are out of range. In any case, you don't need arrays for this.– Kusalananda
3 hours ago
|
show 10 more comments
0
active
oldest
votes
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%2f505226%2fhow-can-use-the-loop-variable-to-create-an-array-with-the-current-iteration-in-a%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
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%2f505226%2fhow-can-use-the-loop-variable-to-create-an-array-with-the-current-iteration-in-a%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
It's not clear to me what you expect to happen here:
NR
is the record (line) number - if you want to loop over columns (fields) the variable you need to refer to in your loop isNF
; in any case, both will be zero inside aBEGIN
block– steeldriver
5 hours ago
Do you have an example where you actually need to store all the files data before processing it from your arrays in the
END
block? What's stopping you from just storing$0
from each line and then usingsplit()
on these later in that case?– Kusalananda
5 hours ago
Hello, ok I think that what is doing for example the first array1[NR]=$3 is storing into record all the information from column 3, which is what I want, the thing is that I have 139 columns so I don't want to declare every array manually. That is what I want to create all 139 arrays using a for loop and using the current value of iteration, for example when i=1 create an array called array1, and so on.
– Eduardo Santiago López
4 hours ago
1
At least if you have a fairly recent version of GNU awk, you can use Arrays of Arrays
– steeldriver
4 hours ago
1
You have 7 lines of input that produces about 14 lines of output. The values for
value
don't make sense. I'm utterly confused. Are the last column timestamps? They are out of range. In any case, you don't need arrays for this.– Kusalananda
3 hours ago