multiple records

This is a discussion on multiple records within the awk forums in Programming Languages category; Hi, I have output which looks as follows abc @ xyz blah blah something something something othersomething othersomtheing othersomething and the above 3 line repeated for some 100 times(with different setting) so i have 300 lines. I want to get print abc @ xyz from 1st lineHi, I have output which looks as follows abc @ xyz blah blah something something something othersomething othersomtheing othersomething and the above 3 line repeated for some 100 times(with different setting) so i have 300 lines. I want to get print abc @ xyz from 1st line...

Go Back   Application Development Forum > Programming Languages > awk

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 07-13-2008, 02:15 AM
nhgokulprasad@gmail.com
Guest
 
Default multiple records

Hi,

I have output which looks as follows
abc@xyz blah blah
something something something
othersomething othersomtheing othersomething

and the above 3 line repeated for some 100 times(with different
setting) so i have 300 lines. I want to get print
abc@xyz from 1st lineHi,

I have output which looks as follows
abc@xyz blah blah
something something something
othersomething othersomtheing othersomething

and the above 3 line repeated for some 100 times(with different
setting) so i have 300 lines. I want to get print
abc@xyz from 1st line
Reply With Quote
  #2  
Old 07-13-2008, 04:12 AM
Janis Papanagnou
Guest
 
Default Re: multiple records

nhgokulprasad@gmail.com wrote:
> Hi,
>
> I have output which looks as follows
> abc@xyz blah blah
> something something something
> othersomething othersomtheing othersomething
>
> and the above 3 line repeated for some 100 times(with different
> setting) so i have 300 lines. I want to get print
> abc@xyz from 1st lineHi,


I suppose you meant the first field from each block of data?

awk 'NR%3==1{print $1}' your_data_file


Janis

>
> I have output which looks as follows
> abc@xyz blah blah
> something something something
> othersomething othersomtheing othersomething
>
> and the above 3 line repeated for some 100 times(with different
> setting) so i have 300 lines. I want to get print
> abc@xyz from 1st line

Reply With Quote
  #3  
Old 07-14-2008, 01:24 AM
nhgokulprasad@gmail.com
Guest
 
Default Re: multiple records

Sorry for confusion let me clear you my problem

I have output which looks as follows
abc@xyz blah blah
something something something
othersomething othersomtheing othersomething

and the above 3 line repeated for some 100 times(with different
setting) so i have 300 lines.

I want to get print
abc@xyz from 1st line
only 3rd field from second and third line. Please help me.
Reply With Quote
  #4  
Old 07-14-2008, 04:21 AM
Kenny McCormack
Guest
 
Default Re: multiple records

In article <b2ffa3ee-baf0-4e60-af7e-8f5d16f9e5ef@y38g2000hsy.googlegroups.com>,
nhgokulprasad@gmail.com <nhgokulprasad@gmail.com> wrote:
>Sorry for confusion let me clear you my problem
>
>I have output which looks as follows
>abc@xyz blah blah
>something something something
>othersomething othersomtheing othersomething
>
>and the above 3 line repeated for some 100 times(with different
>setting) so i have 300 lines.
>
>I want to get print
>abc@xyz from 1st line
>only 3rd field from second and third line. Please help me.


Thanks. That just clarifies everything.

Reply With Quote
  #5  
Old 07-14-2008, 08:06 AM
Janis Papanagnou
Guest
 
Default Re: multiple records

nhgokulprasad@gmail.com wrote:
> Sorry for confusion let me clear you my problem


It doesn't clear your posting...

>
> I have output which looks as follows
> abc@xyz blah blah
> something something something
> othersomething othersomtheing othersomething
>
> and the above 3 line repeated for some 100 times(with different
> setting) so i have 300 lines.


....instead, you gave a new requirement here...

> I want to get print
> abc@xyz from 1st line
> only 3rd field from second and third line. Please help me.


Again, I assume you mean "second and third line" from each 3-line
block?

awk '
NR%3==1 {print $1}
NR%3!=1 {print $3}
' your_data_file

I suppose the above is more apparent to understand how it works,
and if it turns out that you want to print any other field you are
able to adjust the code, but here are some variants...

awk 'NR%3==1 {print $1 ; next} {print $3}' your_data_file

awk '{print (NR%3==1)?$1:$3}' your_data_file

Or shall everything (or every record) be in one line?

Janis
Reply With Quote
  #6  
Old 07-14-2008, 08:25 AM
nhgokulprasad@gmail.com
Guest
 
Default Re: multiple records

Thanks janis it is solved half of my issue

awk '{print (NR%3==1)?$1:$3}' my_file prints in separate line
am trying to get $1 and $3 in same line and other set follows it like

$1 $3(each set)
$1 $3
..
..
..


Reply With Quote
  #7  
Old 07-14-2008, 08:44 AM
Janis Papanagnou
Guest
 
Default Re: multiple records

nhgokulprasad@gmail.com wrote:
> Thanks janis it is solved half of my issue
>
> awk '{print (NR%3==1)?$1:$3}' my_file prints in separate line
> am trying to get $1 and $3 in same line and other set follows it like


Yet another new/changed requirement ???

>
> $1 $3(each set)
> $1 $3
> .
> .
> .
>
>


One last suggestion; type in _exactly_ the first six lines of
sample data and the corresponding desired output. Choose data
that makes it possible to see which input field corresponds to
which output field. Then we will quickly have a solution, be
assured.
Reply With Quote
  #8  
Old 07-14-2008, 02:46 PM
Hermann Peifer
Guest
 
Default Re: multiple records

nhgokulprasad@gmail.com wrote:
> Thanks janis it is solved half of my issue
>
> awk '{print (NR%3==1)?$1:$3}' my_file prints in separate line
> am trying to get $1 and $3 in same line and other set follows it like
>
> $1 $3(each set)
> $1 $3
> .
> .
> .


Here a version where $1 and $3 is on the same line.

$ cat output
abc@xyz blah blah
something1 something2 something3
othersomething1 othersomething2 othersomething3
def@xyz blah blah
something11 something22 something33
othersomething11 othersomething22 othersomething33

$ awk 'NR%3==1{f1=$1;next}{print f1,$3}' output
abc@xyz something3
abc@xyz othersomething3
def@xyz something33
def@xyz othersomething33

Reply With Quote
  #9  
Old 07-15-2008, 03:44 AM
nhgokulprasad@gmail.com
Guest
 
Default Re: multiple records

I really thank all you people. This is really a good place for newbies
to grow next level.

now am trying to dig more to get output in the following format

abc@xyz something3
othersomething3
def@xyz something33
othersomething33

Thanks,

On Jul 14, 11:46*pm, Hermann Peifer <pei...@gmx.eu> wrote:
> nhgokulpra...@gmail.com wrote:
> > Thanks janis it is solved half of my issue

>
> > awk '{print (NR%3==1)?$1:$3}' my_file prints in separate line
> > am trying to get $1 and $3 in same line and other set follows it like

>
> > $1 $3(each set)
> > $1 $3
> > .
> > .
> > .

>
> Here a version where $1 and $3 is on the same line.
>
> $ cat output
> abc@xyz blah blah
> something1 something2 something3
> othersomething1 othersomething2 othersomething3
> def@xyz blah blah
> something11 something22 something33
> othersomething11 othersomething22 othersomething33
>
> $ awk 'NR%3==1{f1=$1;next}{print f1,$3}' output
> abc@xyz something3
> abc@xyz othersomething3
> def@xyz something33
> def@xyz othersomething33


Reply With Quote
  #10  
Old 07-15-2008, 05:54 AM
Hermann Peifer
Guest
 
Default Re: multiple records

[Please don't top-post]

On Jul 15, 9:44 am, "nhgokulpra...@gmail.com"
<nhgokulpra...@gmail.com> wrote:

> On Jul 14, 11:46*pm, Hermann Peifer <pei...@gmx.eu> wrote:
>
>
>
> > nhgokulpra...@gmail.com wrote:
> > > Thanks janis it is solved half of my issue

>
> > > awk '{print (NR%3==1)?$1:$3}' my_file prints in separate line
> > > am trying to get $1 and $3 in same line and other set follows it like

>
> > > $1 $3(each set)
> > > $1 $3
> > > .
> > > .
> > > .

>
> > Here a version where $1 and $3 is on the same line.

>
> > $ cat output
> > abc@xyz blah blah
> > something1 something2 something3
> > othersomething1 othersomething2 othersomething3
> > def@xyz blah blah
> > something11 something22 something33
> > othersomething11 othersomething22 othersomething33

>
> > $ awk 'NR%3==1{f1=$1;next}{print f1,$3}' output
> > abc@xyz something3
> > abc@xyz othersomething3
> > def@xyz something33
> > def@xyz othersomething33- Hide quoted text -

>


> I really thank all you people. This is really a good place for newbies
> to grow next level.
>
> now am trying to dig more to get output in the following format
>
> abc@xyz something3
> othersomething3
> def@xyz something33
> othersomething33
>


This Gawk 3-liner:

gawk '
NR%3==1 {f1=$1 ; next}
NR%3 {print f1,$3 ; next}
{printf "%*s %s\n", length(f1),"",$3} ' output

... prints this:

abc@xyz something3
othersomething3
def@xyz something33
othersomething33

Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 02:27 AM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.