| Register | FAQ | Calendar | Search | Today's Posts | Mark Forums Read |
|
#1
| |||
| |||
| 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 |
|
#2
| |||
| |||
| 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 |
|
#3
| |||
| |||
| 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. |
|
#4
| |||
| |||
| 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. |
|
#5
| |||
| |||
| 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 |
|
#6
| |||
| |||
| Thanks janis it is solved half of my issueawk '{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 .. .. .. |
|
#7
| |||
| |||
| 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. |
|
#8
| |||
| |||
| 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 |
|
#9
| |||
| |||
| 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 |
|
#10
| |||
| |||
| [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 |
![]() |
| Thread Tools | |
| Display Modes | |
In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.