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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Formatting Column to Rows 2

Status
Not open for further replies.

mguha06

Technical User
Apr 20, 2006
28
0
0
US
I have a large series of text in 3 columns and its needs to be formatted to single row of every 12 rows of the columns; example data set.

1867 1 6.40
1867 2 5.90
1867 3 4.70
1867 4 3.70
1867 5 2.50
1867 6 2.20
1867 7 2.40
1867 8 3.20
1867 9 4.30
1867 10 5.20
1867 11 5.90
1867 12 6.90
1868 1 6.40
1868 2 5.90
1868 3 4.70
1868 4 3.70
1868 5 2.50
1868 6 2.20
1868 7 2.40
1868 8 3.20
1868 9 4.30
1868 10 5.20
1868 11 5.90
1868 12 2.50

The final format should look like this:

6.40 5.90 4.70 3.70 2.50 2.20 2.40 3.20 4.30 5.20 5.90 6.90 1867
6.40 5.90 4.70 3.70 2.50 2.20 2.40 3.20 4.30 5.20 5.90 2.50 1868

Thus, every 12 rows is selected and the data from the 3rd column is put into one row and the date from 1st column is put at the end of the rows. The second column is discarded. Can anyone provide a quick approach as how I can implement in awk95.
Appreciate a lot for the help. Definitely will provide stars.
Thanks.


 
Try this
Code:
BEGIN{j=0}
{
  a[j]=$3
  if (j==0) n=$1
  j++
  if (j==12) {
    for (i=0;i<j;i++) printf("%s ", a[i])
    print n
    j=0
  }
}

CaKiwi
 
You may use this program:
Code:
{x=x $3" "}$2==12{print x $1;x=""}

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top