Go Back   Rhinocerus > Newsgroup > Newsgroup comp.lang.* 1 > Newsgroup comp.lang.awk

Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 11-26-2009, 05:22 AM
Perl baby
Guest
 
Posts: n/a
Default Print xth column of yth line

I have a file having fields in a matrix fashion.
What are the different ways in which I can print 3rd column of 5th row
(i.e. NF =3 and line = 5)??

Thanks
Awk baby
Reply With Quote
Alt Today
Advertising
 
and become member of Rhinocerus
Standard Sponsored Links

  #2 (permalink)  
Old 11-26-2009, 06:19 AM
Hermann Peifer
Guest
 
Posts: n/a
Default Re: Print xth column of yth line

Perl baby wrote:
> I have a file having fields in a matrix fashion.
> What are the different ways in which I can print 3rd column of 5th row
> (i.e. NF =3 and line = 5)??
>


How many different ways of printing would you need?

Hermann
Reply With Quote
  #3 (permalink)  
Old 11-26-2009, 07:14 AM
Perl baby
Guest
 
Posts: n/a
Default Re: Print xth column of yth line

On Nov 26, 12:19 pm, Hermann Peifer <pei...@gmx.eu> wrote:
> Perl baby wrote:
> > I have a file having fields in a matrix fashion.
> > What are the different ways in which I can print 3rd column of 5th row
> > (i.e. NF =3 and line = 5)??

>
> How many different ways of printing would you need?
>
> Hermann


Wud be gr8 if u cud gimme atleast one.

Thanks
Awk Baby
Reply With Quote
  #4 (permalink)  
Old 11-26-2009, 07:27 AM
Grant
Guest
 
Posts: n/a
Default Re: Print xth column of yth line

On Thu, 26 Nov 2009 00:14:31 -0800 (PST), Perl baby <whereismelvin@gmail.com> wrote:

>On Nov 26, 12:19 pm, Hermann Peifer <pei...@gmx.eu> wrote:
>> Perl baby wrote:
>> > I have a file having fields in a matrix fashion.
>> > What are the different ways in which I can print 3rd column of 5th row
>> > (i.e. NF =3 and line = 5)??

>>
>> How many different ways of printing would you need?
>>
>> Hermann

>
>Wud be gr8 if u cud gimme atleast one.


Like:

awk 'NR == 5 {print $3}' file

Grant.
--
http://bugsplatter.id.au
Reply With Quote
  #5 (permalink)  
Old 11-26-2009, 07:30 AM
Hermann Peifer
Guest
 
Posts: n/a
Default Re: Print xth column of yth line

Perl baby wrote:
> On Nov 26, 12:19 pm, Hermann Peifer <pei...@gmx.eu> wrote:
>> Perl baby wrote:
>>> I have a file having fields in a matrix fashion.
>>> What are the different ways in which I can print 3rd column of 5th row
>>> (i.e. NF =3 and line = 5)??

>> How many different ways of printing would you need?
>>
>> Hermann

>
> Wud be gr8 if u cud gimme atleast one.
>


Try out how far you get with

awk 'NR==5{print $3}' file

Hermann
Reply With Quote
  #6 (permalink)  
Old 11-26-2009, 10:46 AM
Loki Harfagr
Guest
 
Posts: n/a
Default Re: Print xth column of yth line

Thu, 26 Nov 2009 19:27:55 +1100, Grant did catÂ*:

> On Thu, 26 Nov 2009 00:14:31 -0800 (PST), Perl baby
> <whereismelvin@gmail.com> wrote:
>
>>On Nov 26, 12:19 pm, Hermann Peifer <pei...@gmx.eu> wrote:
>>> Perl baby wrote:
>>> > I have a file having fields in a matrix fashion. What are the
>>> > different ways in which I can print 3rd column of 5th row (i.e. NF
>>> > =3 and line = 5)??
>>>
>>> How many different ways of printing would you need?
>>>
>>> Hermann

>>
>>Wud be gr8 if u cud gimme atleast one.

>
> Like:
>
> awk 'NR == 5 {print $3}' file
>
> Grant.


let's play "flog" for a change ;-)
---------
awk -v col=3 -v row=5 '
FNR>row{
print a
exit
}
FNR!=row{ next}
{
for(i=NF;i;--i){
if(i>col){continue}
if(i<col){break}
a=$(i)
}
}
' yerfile
---------
Reply With Quote
  #7 (permalink)  
Old 11-26-2009, 12:03 PM
Lorenz
Guest
 
Posts: n/a
Default Re: Print xth column of yth line

Loki Harfagr wrote:
>---------
>awk -v col=3 -v row=5 '
>FNR>row{
> print a
> exit
>}
>FNR!=row{ next}
>{
> for(i=NF;i;--i){
> if(i>col){continue}
> if(i<col){break}
> a=$(i)
> }
>}
>' yerfile
>---------



awk -v col=3 -v row=5 'FNR==row {print $(col); exit}' myfile
--

Lorenz
Reply With Quote
  #8 (permalink)  
Old 11-26-2009, 05:36 PM
Loki Harfagr
Guest
 
Posts: n/a
Default Re: Print xth column of yth line

Thu, 26 Nov 2009 13:03:22 +0000, Lorenz did catÂ*:

> Loki Harfagr wrote:
>>---------
>>awk -v col=3 -v row=5 '
>>FNR>row{
>> print a
>> exit
>>}
>>FNR!=row{ next}
>>{
>> for(i=NF;i;--i){
>> if(i>col){continue}
>> if(i<col){break}
>> a=$(i)
>> }
>>}
>>' yerfile
>>---------

>
>
> awk -v col=3 -v row=5 'FNR==row {print $(col); exit}' myfile


Well yes indeed but it may show you may have missed the
"let's play 'flog' for a change ;-)" part?

as the OP wanted an undefinite number of solutions
here's another 'flog' way ,-)
---------
awk -v col=3 -v row=5 '
!(FNR-row){
split($0,v)
a=v[col]
print a
exit
}
FNR-row{
next
}
---------
Reply With Quote
  #9 (permalink)  
Old 11-27-2009, 06:33 AM
Lorenz
Guest
 
Posts: n/a
Default Re: Print xth column of yth line

Loki Harfagr wrote:
>Thu, 26 Nov 2009 13:03:22 +0000, Lorenz did cat*:
>[...]
> Well yes indeed but it may show you may have missed the
>"let's play 'flog' for a change ;-)" part?


that may be (due to lack in knowledge about english proverbs)


Lorenz (allready thinking about a getline version 8-)
Reply With Quote
  #10 (permalink)  
Old 11-27-2009, 08:12 AM
Grant
Guest
 
Posts: n/a
Default Re: Print xth column of yth line

On Fri, 27 Nov 2009 07:33:13 +0000, Lorenz <lorenznl@yahoo.com> wrote:

>Loki Harfagr wrote:
>>Thu, 26 Nov 2009 13:03:22 +0000, Lorenz did catÂ*:
>>[...]
>> Well yes indeed but it may show you may have missed the
>>"let's play 'flog' for a change ;-)" part?

>
>that may be (due to lack in knowledge about english proverbs)


echo flog |rev

Loki's from .fr

>
>
>Lorenz (allready thinking about a getline version 8-)


The boggle minds...

Grant.
--
http://bugsplatter.id.au
Reply With Quote
  #11 (permalink)  
Old 11-27-2009, 09:24 AM
Loki Harfagr
Guest
 
Posts: n/a
Default Re: Print xth column of yth line

Fri, 27 Nov 2009 20:12:45 +1100, Grant did catÂ*:

> On Fri, 27 Nov 2009 07:33:13 +0000, Lorenz <lorenznl@yahoo.com> wrote:
>
>>Loki Harfagr wrote:
>>>Thu, 26 Nov 2009 13:03:22 +0000, Lorenz did catÂ*: [...]
>>> Well yes indeed but it may show you may have missed the
>>>"let's play 'flog' for a change ;-)" part?

>>
>>that may be (due to lack in knowledge about english proverbs)

>
> echo flog |rev
>
> Loki's from .fr


yup, and that'd make me a frog, maybe the reason why
flog's a natural ;-)
Or maybe Lorenz was thinking to that amelican plovelb?
"Can't tell by looking at a flog how high he will jump."

>>
>>Lorenz (allready thinking about a getline version 8-)


Noooo, get back!-)

>
> The boggle minds...


as you requested boggle here's a last and boggling flog,
I promise I won't push any other after that one ;-)
-----------
awk -v col=3 -v row=5 '
{
row--
while(++i){
a[++n]=$(i)
if($(i)~/[\n]/){
row--
}
if(!row){
while(++i){
a[++n]=$(i)
if($(i)~/[ \t]/){
col--
if(!col){
for(p=n-1;p;p--){
printf("%s", a[n-p])
}
printf("%s","\n")
exit
}
n=0
delete(a)
}
}
}
}
}
' RS= FS= yerfile
-----------
Reply With Quote
  #12 (permalink)  
Old 11-27-2009, 12:59 PM
OX0spy
Guest
 
Posts: n/a
Default Re: Print xth column of yth line

On Nov 27, 6:24*pm, Loki Harfagr <l...@thedarkdesign.free.fr.INVALID>
wrote:
> Fri, 27 Nov 2009 20:12:45 +1100, Grant did cat*:
>
> > On Fri, 27 Nov 2009 07:33:13 +0000, Lorenz <loren...@yahoo.com> wrote:

>
> >>Loki Harfagr wrote:
> >>>Thu, 26 Nov 2009 13:03:22 +0000, Lorenz did cat*: [...]
> >>> Well yes indeed but it may show you may have missed the
> >>>"let's play 'flog' for a change ;-)" part?

>
> >>that may be (due to lack in knowledge about english proverbs)

>
> > echo flog |rev

>
> > Loki's from .fr

>
> yup, and that'd make me a frog, maybe the reason why
> flog's a natural ;-)
> Or maybe Lorenz was thinking to that amelican plovelb?
> "Can't tell by looking at a flog how high he will jump."
>
>
>
> >>Lorenz (allready thinking about a getline version 8-)

>
> Noooo, get back!-)
>
>
>
> > The boggle minds...

>
> as you requested boggle here's a last and boggling flog,
> I promise I won't push any other after that one ;-)
> -----------
> awk -v col=3 -v row=5 '
> {
> * * * * row--
> * * * * while(++i){
> * * * * * * * * a[++n]=$(i)
> * * * * * * * * if($(i)~/[\n]/){
> * * * * * * * * * * * * row--
> * * * * * * * * }
> * * * * * * * * if(!row){
> * * * * * * * * * * * * while(++i){
> * * * * * * * * * * * * * * * * a[++n]=$(i)
> * * * * * * * * * * * * * * * * if($(i)~/[ \t]/){
> * * * * * * * * * * * * * * * * * * * * col--
> * * * * * * * * * * * * * * * * * * * * if(!col){
> * * * * * * * * * * * * * * * * * * * * * * * * for(p=n-1;p;p--){
> * * * * * * * * * * * * * * * * * * * * * * * * * * * * printf("%s", a[n-p])
> * * * * * * * * * * * * * * * * * * * * * * * * }
> * * * * * * * * * * * * * * * * * * * * * * * * printf("%s","\n")
> * * * * * * * * * * * * * * * * * * * * * * * * exit
> * * * * * * * * * * * * * * * * * * * * }
> * * * * * * * * * * * * * * * * * * * * n=0
> * * * * * * * * * * * * * * * * * * * * delete(a)
> * * * * * * * * * * * * * * * * }
> * * * * * * * * * * * * }
> * * * * * * * * }
> * * * * }}
>
> ' RS= FS= yerfile
> -----------


awk -v LINE=2 -v COLUMN=5 'NR==LINE {print substr($0, COLUMN, 1);
exit}'
Reply With Quote
  #13 (permalink)  
Old 11-27-2009, 12:59 PM
OX0spy
Guest
 
Posts: n/a
Default Re: Print xth column of yth line

On Nov 27, 6:24*pm, Loki Harfagr <l...@thedarkdesign.free.fr.INVALID>
wrote:
> Fri, 27 Nov 2009 20:12:45 +1100, Grant did cat*:
>
> > On Fri, 27 Nov 2009 07:33:13 +0000, Lorenz <loren...@yahoo.com> wrote:

>
> >>Loki Harfagr wrote:
> >>>Thu, 26 Nov 2009 13:03:22 +0000, Lorenz did cat*: [...]
> >>> Well yes indeed but it may show you may have missed the
> >>>"let's play 'flog' for a change ;-)" part?

>
> >>that may be (due to lack in knowledge about english proverbs)

>
> > echo flog |rev

>
> > Loki's from .fr

>
> yup, and that'd make me a frog, maybe the reason why
> flog's a natural ;-)
> Or maybe Lorenz was thinking to that amelican plovelb?
> "Can't tell by looking at a flog how high he will jump."
>
>
>
> >>Lorenz (allready thinking about a getline version 8-)

>
> Noooo, get back!-)
>
>
>
> > The boggle minds...

>
> as you requested boggle here's a last and boggling flog,
> I promise I won't push any other after that one ;-)
> -----------
> awk -v col=3 -v row=5 '
> {
> * * * * row--
> * * * * while(++i){
> * * * * * * * * a[++n]=$(i)
> * * * * * * * * if($(i)~/[\n]/){
> * * * * * * * * * * * * row--
> * * * * * * * * }
> * * * * * * * * if(!row){
> * * * * * * * * * * * * while(++i){
> * * * * * * * * * * * * * * * * a[++n]=$(i)
> * * * * * * * * * * * * * * * * if($(i)~/[ \t]/){
> * * * * * * * * * * * * * * * * * * * * col--
> * * * * * * * * * * * * * * * * * * * * if(!col){
> * * * * * * * * * * * * * * * * * * * * * * * * for(p=n-1;p;p--){
> * * * * * * * * * * * * * * * * * * * * * * * * * * * * printf("%s", a[n-p])
> * * * * * * * * * * * * * * * * * * * * * * * * }
> * * * * * * * * * * * * * * * * * * * * * * * * printf("%s","\n")
> * * * * * * * * * * * * * * * * * * * * * * * * exit
> * * * * * * * * * * * * * * * * * * * * }
> * * * * * * * * * * * * * * * * * * * * n=0
> * * * * * * * * * * * * * * * * * * * * delete(a)
> * * * * * * * * * * * * * * * * }
> * * * * * * * * * * * * }
> * * * * * * * * }
> * * * * }}
>
> ' RS= FS= yerfile
> -----------


awk -v LINE=2 -v COLUMN=5 'NR==LINE {print substr($0, COLUMN, 1);
exit}'
Reply With Quote
  #14 (permalink)  
Old 11-27-2009, 01:01 PM
OX0spy
Guest
 
Posts: n/a
Default Re: Print xth column of yth line

On Nov 27, 6:24*pm, Loki Harfagr <l...@thedarkdesign.free.fr.INVALID>
wrote:
> Fri, 27 Nov 2009 20:12:45 +1100, Grant did cat*:
>
> > On Fri, 27 Nov 2009 07:33:13 +0000, Lorenz <loren...@yahoo.com> wrote:

>
> >>Loki Harfagr wrote:
> >>>Thu, 26 Nov 2009 13:03:22 +0000, Lorenz did cat*: [...]
> >>> Well yes indeed but it may show you may have missed the
> >>>"let's play 'flog' for a change ;-)" part?

>
> >>that may be (due to lack in knowledge about english proverbs)

>
> > echo flog |rev

>
> > Loki's from .fr

>
> yup, and that'd make me a frog, maybe the reason why
> flog's a natural ;-)
> Or maybe Lorenz was thinking to that amelican plovelb?
> "Can't tell by looking at a flog how high he will jump."
>
>
>
> >>Lorenz (allready thinking about a getline version 8-)

>
> Noooo, get back!-)
>
>
>
> > The boggle minds...

>
> as you requested boggle here's a last and boggling flog,
> I promise I won't push any other after that one ;-)
> -----------
> awk -v col=3 -v row=5 '
> {
> * * * * row--
> * * * * while(++i){
> * * * * * * * * a[++n]=$(i)
> * * * * * * * * if($(i)~/[\n]/){
> * * * * * * * * * * * * row--
> * * * * * * * * }
> * * * * * * * * if(!row){
> * * * * * * * * * * * * while(++i){
> * * * * * * * * * * * * * * * * a[++n]=$(i)
> * * * * * * * * * * * * * * * * if($(i)~/[ \t]/){
> * * * * * * * * * * * * * * * * * * * * col--
> * * * * * * * * * * * * * * * * * * * * if(!col){
> * * * * * * * * * * * * * * * * * * * * * * * * for(p=n-1;p;p--){
> * * * * * * * * * * * * * * * * * * * * * * * * * * * * printf("%s", a[n-p])
> * * * * * * * * * * * * * * * * * * * * * * * * }
> * * * * * * * * * * * * * * * * * * * * * * * * printf("%s","\n")
> * * * * * * * * * * * * * * * * * * * * * * * * exit
> * * * * * * * * * * * * * * * * * * * * }
> * * * * * * * * * * * * * * * * * * * * n=0
> * * * * * * * * * * * * * * * * * * * * delete(a)
> * * * * * * * * * * * * * * * * }
> * * * * * * * * * * * * }
> * * * * * * * * }
> * * * * }}
>
> ' RS= FS= yerfile
> -----------


awk -v LINE=2 -v COLUMN=5 'NR==LINE {print substr($0, COLUMN, 1)}'
Reply With Quote
 
Reply

Popular Tags in the Forum
column, line, print, xth, yth

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Treedisc Macro Alex Murphy Newsgroup comp.soft-sys.sas 0 04-28-2009 07:04 AM
client-server socket script that crashes on Mac Bad Mutha Hubbard Newsgroup comp.lang.python 0 04-16-2009 01:35 AM
Windows command line not displaying print commands JonathanB Newsgroup comp.lang.python 8 03-31-2009 01:59 PM
PROC REPORT and LINE statement Tom Hide Newsgroup comp.soft-sys.sas 0 08-03-2005 06:39 PM
Re: Solution: PROC REPORT and LINE statement Tom Hide Newsgroup comp.soft-sys.sas 0 08-01-2005 07:52 AM



All times are GMT. The time now is 04:28 PM.


Copyright ©2009

LinkBacks Enabled by vBSEO 3.3.0 RC2 © 2009, Crawlability, Inc.