I am a AWK beginner and after playing around with the built-in variable NR, I do not understand the following Text:
CREDITS,EXPDATE,USER,GROUPS
99,01 jun 2018,sylvain,team:::admin
52,01 dec 2018,sonia,team
52,01 dec 2018,sonia,team
using
awk 'NR' file
CREDITS,EXPDATE,USER,GROUPS
99,01 jun 2018,sylvain,team:::admin
52,01 dec 2018,sonia,team
52,01 dec 2018,sonia,team
awk '{print NR}' file
1
2
3
4
Thus, I was expecting to the same results when using NR>2&&NR<5. Here is what I got:
awk 'NR>2&&NR<5' file
52,01 dec 2018,sonia,team
52,01 dec 2018,sonia,team
awk '{print NR>2&&NR<5}' file
Nothing shows up
Could you tell me why isn“t the last line showing a count from the numbers to 3 to 4 as it is displayed when using awk '{print NR}' file? It is not possible to mix a range of NR with the command print?
Thanks in advance!
awk 'NR>2&&NR<5' Input_fileis where we are checking condition if line number is greater than 2 and greater than 5 then do default action which is printing current line.In you code
awk '{print NR>2&&NR<5}' Input_file, here you are using print and then mentioning condition which is NOT the way awk works.awk works on method of:
if NO action is given then by default print of current line will happen, which is happening in your first code.
More analysis: To prove point
{print NR>2&&NR<5}will NOT behave like default method ofawkofregexp/condition_check{action}run this:See the output what it will provide:
See line 3rd and 4th which is
1means condition for that line is TRUE and0means condition for that line is FALSE. So by this we could see it prints condition's STATE inprintstatement if we use condition in(..)like mentioned above.