Why only one side of NR work? [duplicate]

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite













This question already has an answer here:



  • How to insert bash variables in awk?

    3 answers



  • Using bash variable with escape character in awk to extract lines from file

    1 answer



I am very confused about one simple script with awk: I want to print a range of rows by passing variables, the script below works:



awk ' if (NR >10 && NR < 100 ) print $0 ' file


the script below works too:



set fac = 10
awk ' if (NR >$fac && NR < 100 ) print $0 ' file


BUT this script NOT works, WHY? I am so confused. thank you for help.



set fac = 100
awk ' if (NR >10 && NR <$fac ) print $0 ' file






share|improve this question











marked as duplicate by Thomas Dickey, jasonwryan, αғsнιη, muru, Kiwy Jun 14 at 10:27


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • There are many duplicates for this...
    – Thomas Dickey
    Jun 14 at 1:13






  • 1




    also I don't think so your second commmad does works, it will be NR >0 && NR < 100 and you will getting first 99 lines and third command NR >10 && NR <0 and since no NR is <0 then it won't print anything at all
    – Î±Ò“sнιη
    Jun 14 at 1:52











  • @ThomasDickey, thank you. With your hint, I figure out how to get it work by adding "-v" like below, but still not sure why the second script work? awk -v a="$fac1" -v b="$fac2" 'if (NR>a && NR<b) print $0'
    – kelly
    Jun 14 at 2:07















up vote
0
down vote

favorite













This question already has an answer here:



  • How to insert bash variables in awk?

    3 answers



  • Using bash variable with escape character in awk to extract lines from file

    1 answer



I am very confused about one simple script with awk: I want to print a range of rows by passing variables, the script below works:



awk ' if (NR >10 && NR < 100 ) print $0 ' file


the script below works too:



set fac = 10
awk ' if (NR >$fac && NR < 100 ) print $0 ' file


BUT this script NOT works, WHY? I am so confused. thank you for help.



set fac = 100
awk ' if (NR >10 && NR <$fac ) print $0 ' file






share|improve this question











marked as duplicate by Thomas Dickey, jasonwryan, αғsнιη, muru, Kiwy Jun 14 at 10:27


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • There are many duplicates for this...
    – Thomas Dickey
    Jun 14 at 1:13






  • 1




    also I don't think so your second commmad does works, it will be NR >0 && NR < 100 and you will getting first 99 lines and third command NR >10 && NR <0 and since no NR is <0 then it won't print anything at all
    – Î±Ò“sнιη
    Jun 14 at 1:52











  • @ThomasDickey, thank you. With your hint, I figure out how to get it work by adding "-v" like below, but still not sure why the second script work? awk -v a="$fac1" -v b="$fac2" 'if (NR>a && NR<b) print $0'
    – kelly
    Jun 14 at 2:07













up vote
0
down vote

favorite









up vote
0
down vote

favorite












This question already has an answer here:



  • How to insert bash variables in awk?

    3 answers



  • Using bash variable with escape character in awk to extract lines from file

    1 answer



I am very confused about one simple script with awk: I want to print a range of rows by passing variables, the script below works:



awk ' if (NR >10 && NR < 100 ) print $0 ' file


the script below works too:



set fac = 10
awk ' if (NR >$fac && NR < 100 ) print $0 ' file


BUT this script NOT works, WHY? I am so confused. thank you for help.



set fac = 100
awk ' if (NR >10 && NR <$fac ) print $0 ' file






share|improve this question












This question already has an answer here:



  • How to insert bash variables in awk?

    3 answers



  • Using bash variable with escape character in awk to extract lines from file

    1 answer



I am very confused about one simple script with awk: I want to print a range of rows by passing variables, the script below works:



awk ' if (NR >10 && NR < 100 ) print $0 ' file


the script below works too:



set fac = 10
awk ' if (NR >$fac && NR < 100 ) print $0 ' file


BUT this script NOT works, WHY? I am so confused. thank you for help.



set fac = 100
awk ' if (NR >10 && NR <$fac ) print $0 ' file




This question already has an answer here:



  • How to insert bash variables in awk?

    3 answers



  • Using bash variable with escape character in awk to extract lines from file

    1 answer









share|improve this question










share|improve this question




share|improve this question









asked Jun 14 at 1:09









kelly

133




133




marked as duplicate by Thomas Dickey, jasonwryan, αғsнιη, muru, Kiwy Jun 14 at 10:27


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






marked as duplicate by Thomas Dickey, jasonwryan, αғsнιη, muru, Kiwy Jun 14 at 10:27


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.













  • There are many duplicates for this...
    – Thomas Dickey
    Jun 14 at 1:13






  • 1




    also I don't think so your second commmad does works, it will be NR >0 && NR < 100 and you will getting first 99 lines and third command NR >10 && NR <0 and since no NR is <0 then it won't print anything at all
    – Î±Ò“sнιη
    Jun 14 at 1:52











  • @ThomasDickey, thank you. With your hint, I figure out how to get it work by adding "-v" like below, but still not sure why the second script work? awk -v a="$fac1" -v b="$fac2" 'if (NR>a && NR<b) print $0'
    – kelly
    Jun 14 at 2:07

















  • There are many duplicates for this...
    – Thomas Dickey
    Jun 14 at 1:13






  • 1




    also I don't think so your second commmad does works, it will be NR >0 && NR < 100 and you will getting first 99 lines and third command NR >10 && NR <0 and since no NR is <0 then it won't print anything at all
    – Î±Ò“sнιη
    Jun 14 at 1:52











  • @ThomasDickey, thank you. With your hint, I figure out how to get it work by adding "-v" like below, but still not sure why the second script work? awk -v a="$fac1" -v b="$fac2" 'if (NR>a && NR<b) print $0'
    – kelly
    Jun 14 at 2:07
















There are many duplicates for this...
– Thomas Dickey
Jun 14 at 1:13




There are many duplicates for this...
– Thomas Dickey
Jun 14 at 1:13




1




1




also I don't think so your second commmad does works, it will be NR >0 && NR < 100 and you will getting first 99 lines and third command NR >10 && NR <0 and since no NR is <0 then it won't print anything at all
– Î±Ò“sнιη
Jun 14 at 1:52





also I don't think so your second commmad does works, it will be NR >0 && NR < 100 and you will getting first 99 lines and third command NR >10 && NR <0 and since no NR is <0 then it won't print anything at all
– Î±Ò“sнιη
Jun 14 at 1:52













@ThomasDickey, thank you. With your hint, I figure out how to get it work by adding "-v" like below, but still not sure why the second script work? awk -v a="$fac1" -v b="$fac2" 'if (NR>a && NR<b) print $0'
– kelly
Jun 14 at 2:07





@ThomasDickey, thank you. With your hint, I figure out how to get it work by adding "-v" like below, but still not sure why the second script work? awk -v a="$fac1" -v b="$fac2" 'if (NR>a && NR<b) print $0'
– kelly
Jun 14 at 2:07
















active

oldest

votes






















active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes

Popular posts from this blog

How to check contact read email or not when send email to Individual?

Bahrain

Postfix configuration issue with fips on centos 7; mailgun relay