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!

Loop, calculate and print problem

Status
Not open for further replies.

mrr

Technical User
May 3, 2001
67
US
Hello,
I have been trying to create a script that will take a tab delimited file with fields that are sometimes null or blank and stack the column info into separate records with different x/y coordinate positions. The first record of text1 would have a slightly different y value than the following records of text2,text3,etc.

My data file looks like this:
The input format is tab delimited.
First record is a header description only, ignore it.
x y data data data data data id
0 0 text1 text2 text3 "9,999" "-14,000" 1
10 20 text1 text3 "9,999" "-14,000" 2
20 30 text1 text2 "9,999" "-14,000" 3

I would like it to look like this result:
The output is also tab delimited.

10 11 text1
10 9 text2
10 8 text3
10 7 "9,999"
10 6 "-14,000"
10 5 1
20 31 text1
20 29 text3
20 28 "9,999"
20 27 "-14,000"
20 26 2
30 41 text1
30 39 text2
30 38 "9,999"
30 37 "-14,000"
30 36 3

I have had some luck in reformating the data from record input into a stacked format using
for (i=3;i<=NF;i++) print x+10;y+20,$i;

except here's the problem:
I need to always add a constant of 10 to the x, and slightly offset the y coordinate of the text1 record with a different y increment than the following text items for that group.
If the group of text items is minus or blank the script would continue with the next item in a neat stack of text info with no blank lines.

Thanks for any ideas.


 
This seems to work. Put tabs between the &quot; &quot; pairs in the print statement.
Code:
{
  if (NR == 1) next
  x = $1 + 10;
  for (i=3;i<=NF;i++) {
    if ($i !~ / +/) {
      y = $2 + 13 -i
      if (i==3) y++
      print x &quot; &quot; y &quot; &quot; $i
    }
  }
}
Hope this helps. CaKiwi
 
CaKiwi,
Thanks alot for the help on this.
It works just like I had planned.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top