Awk will process each file in turn line by line. Awk will keep track of the current line number in the current file ( FNR variable) and also the total number of lines seen so far ( NR variable). The condition FNR==NR can only be true while awk is reading the first file.
Up vote 1 down vote favorite share g+ share fb share tw.
I used the awk one liner from this question to solve a problem of mine that was similar. However, not really knowing Awk I have no idea how it works. Can anyone explain how the script functions?
I'd like to understand it so I can apply it in different situations. Below is the one liner from the link: awk 'FNR==NR{aNR=$3;next}{$2=aFNR}1' f2 f1 I know that FNR=NR part of it is what makes sure that the lines in file one are matched to the same line number in file 2. And obviously $3 and $2 correspond to the third and second fields respectively.
But I am perplexed what the "1" at the end of the code does and I'm a bit confused by the "a". I assume it represents the file names. Awk link|improve this question asked Mar 23 at 15:58phileas fogg45019 71% accept rate.
The a is the name of the array variable. 1 is shorthand for {print} – potong Mar 23 at 16:35.
Awk will process each file in turn line by line. Awk will keep track of the current line number in the current file (FNR variable) and also the total number of lines seen so far (NR variable). The condition FNR==NR can only be true while awk is reading the first file.
ANR=$3 sets the array element indexed at NR to hold the value of the third field. An awk program is largely composed of condition {action} pairs. For the current line, each condition is checked and if true then the action block is executed.
If the condition is missing, the action block will be executed -- this is the case for the {$2=aFNR} block. If the condition is present but the action block is absent, the default action is to print $0 which is the current line after any transformations. Since a non-zero number is equivalent to true, then 1 instructs awk to perform the default action for every line.
The reason the first file is not printed is due to the next instruction in the first block.
Thanks! I appreciate the detailed answer. That clears things up for me.
– phileas fogg Mar 23 at 20:45.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.