Re: [ask] awk - passing for loop bash variables to awk

2012-09-17 Thread Morning Star
On Mon, Sep 17, 2012 at 7:57 AM, Cam Hutchison wrote: > When awk runs, it reads its input until EOF. In your loop, the first run > of awk is consuming all the input from stdin (cat input) and printing > the first line. For the subsequent iterations through the loop, awk no > longer has anything to

Re: [ask] awk - passing for loop bash variables to awk

2012-09-16 Thread Cam Hutchison
Morning Star writes: >here is the desired output: >line_1 >line_2 >line_3 >here is what i do: >cat input | for (( i=1;i<=3;i++ )); do gawk -v var=$i 'NR == var { print}'; >done >but, the result is always: >line_1 When awk runs, it reads its input until EOF. In your loop, the first run of awk

Re: [ask] awk - passing for loop bash variables to awk

2012-09-16 Thread Morning Star
On Sun, Sep 16, 2012 at 4:28 PM, Christofer C. Bell wrote: > $ for (( i=1;i<=3;i++ )); do gawk -v var=$i 'NR == var { print}' input ; done > > You're asking awk to read lines from a file, so you need to give the > file over to awk. The above gives you the output you're looking for. > The bash po

Re: [ask] awk - passing for loop bash variables to awk

2012-09-16 Thread Christofer C. Bell
On Sun, Sep 16, 2012 at 3:44 AM, Morning Star wrote: > Hi guys, > I get a difficulty to produce the desired output using awk. i want to > use for loop bash variable as the input to the awk variable > here is the illustrated input: > > line_1 > line_2 > line_3 > line_4 > line_5 > line_6 > line_7 >

Re: [ask] awk - passing for loop bash variables to awk

2012-09-16 Thread Morning Star
On Sun, Sep 16, 2012 at 3:53 PM, Teemu Likonen wrote: > Maybe not what you are asking for but one can get the desired output > with these: > > $ awk 'NR >= 1 && NR <= 3 { print }' inputfile > > $ head -n3 inputfile > > $ sed -n 1,3p inputfile > thanks, Teemu. i already know that, but

Re: [ask] awk - passing for loop bash variables to awk

2012-09-16 Thread Morning Star
On Sun, Sep 16, 2012 at 4:14 PM, emmanuel segura wrote: > awk '/line/ {print; if(FNR % 3 == 0){exit}}' var > thanks, emmanuel. i already know that, but right now i need to understand how passing for loop bash variables to awk works. -- To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.

Re: [ask] awk - passing for loop bash variables to awk

2012-09-16 Thread Morning Star
On Sun, Sep 16, 2012 at 3:59 PM, Alex Hutton wrote: > I would do : > cat input | head -n3 > thanks, alex. i already know that, but right now i need to understand how passing for loop bash variables to awk works. -- To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org with a subject

Re: [ask] awk - passing for loop bash variables to awk

2012-09-16 Thread Teemu Likonen
Morning Star [2012-09-16 15:44:05 +0700] wrote: > I get a difficulty to produce the desired output using awk. i want to > use for loop bash variable as the input to the awk variable here is > the illustrated input: > here is the desired output: > line_1 > line_2 > line_3 > > here is what i do: >

[ask] awk - passing for loop bash variables to awk

2012-09-16 Thread Morning Star
Hi guys, I get a difficulty to produce the desired output using awk. i want to use for loop bash variable as the input to the awk variable here is the illustrated input: line_1 line_2 line_3 line_4 line_5 line_6 line_7 line_8 line_9 line_10 here is the desired output: line_1 line_2 line_3 here i