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

problem with awk code

Status
Not open for further replies.

MetStud

Technical User
Nov 7, 2011
1
DE
Dear Users,

i have following input data. See attachment. Now i want to modify my data with this small script but something goes wrong. See line 107 of output data when you run the small script.

There should be written:

2 1 6

but instead there is

2 2 6

is there any way to fix it? I hope you understand what i am trying to do.

Code:
 input=test.b

awk '{print $2,$4,$5,$7}' ${input} > clean.txt

rm out.txt
touch out.txt
typeset -i y
typeset -i counter=0
while read x1 y1 y2 h
do
  counter=counter+1
  if [ $counter -eq 1 ]; then
    for i in `seq $y1 $y2`
    do
      y=$i 
      echo "${x1}  ${y}  ${h}" >> out.txt
    done
  elif [ $counter -gt 1 ]; then
    for i in `seq $(expr $y1 + 1) $y2`
    do
      y=$i
      echo "${x1}  ${y}  ${h}" >> out.txt
    done
  fi

done < clean.txt

Thanks a lot.
 
Why are you posting this in the AWK forum when your code is written in shell?

It is "2 2 6" instead of "2 1 6" because you have specifically written code to make it that way... $(expr $y1 + 1).

Annihilannic
[small]tgmlify - code syntax highlighting for your tek-tips posts[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top