Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trying to combine every 2 lines of huge output file 1

Status
Not open for further replies.

CharlieMac

Technical User
Nov 19, 2008
4
US
I am pretty new to awk and have run into a wall. I have the following input file:
23:59:36 2002 BDDDY 4 2 1 5
23:59:36 2002 BDDDY 4 1 0
23:59:36 2003 BDDDY 4 0 4 13
23:59:36 2003 BDDDY 13 0 0
23:59:36 2004 BDDDY 55 24 20 180
23:59:36 2004 BDDDY 157 23 0
23:59:36 2005 BDDDY 10132 5909 2177 31197
23:59:36 2005 BDDDY 17343 13854 0
23:59:36 2006 BDDDY 8177 5484 7598 27272
23:59:36 2006 BDDDY 14727 12545 0
23:59:36 2007 BDDDY 2459 1367 0 9219
23:59:36 2007 BDDDY 5339 3880 0
23:59:36 2705 BDDDY 1409 702 0 7765
23:59:36 2705 BDDDY 4700 3065 0
23:59:36 2706 BDDDY 4856 2590 0 18078
23:59:36 2706 BDDDY 10844 7234 0
23:59:36 2707 BDDDY 0 0 0 0
23:59:36 2707 BDDDY 0 0 0

what I would like to parse this to make it look like
23:59:36 2002 BDDDY 4 2 1 5 4 1 0
23:59:36 2003 BDDDY 4 0 4 13 13 0 0
23:59:36 2004 BDDDY 55 24 20 180 157 23 0

As you can kind of see it would be all the first line and the last 3 fields of the second line.

any help would be great I have tried the following awk script:
BEGIN {
FS="\n"
RS=""
}
{
print $1 " " $2
}

Granted the output is not perfect but it is workable but it only does the first 2 lines with an output of:

23:59:36 2002 BDDDY 4 2 1 5 23:59:36 2002 BDDDY 4 1 0

only and none of the other lines.

Any help would be GREATLY appreciated.
 
In the awk man page have a look to the % (modulo) operator.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
My man is SunOS 5.9 Last change: 7 Jul 2000
and there is nothing in it regarding the % Operator
 
A starting point:
NR%2==1{x=$0;next}
{print x,$4,$5,$6}

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
WOW!!! Thank you SO much PHV this worked perfect,

Not to bug but can you explain what the % does? I think I understand everything else but I don't understand what the function of the % is.
 
Ohhhhh I get it. I just smacked myself in the back of the head for you..

Thanks again PHV
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top