how to do this


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to do this
# 1  
Old 03-21-2006
Question how to do this

Hi Guys,
I have a file which contains data in the below format.

A1 A2 6
B1 B2 4
My question is ..Is it possible to write a script which reads the above file and gives the result as

A1 A2 1
A1 A2 2
A1 A2 3
.....
A1 A2 6
B1 B2 1
........
B1 B2 4
It would be a great help if any one respond to this with a script or a suggestion.

Thanks in advance
sean
# 2  
Old 03-21-2006
what have u tried so far ?!!! Smilie

Code:
# !/usr/bin/ksh
while read str1 str2 cnt
do
  i=1
  while [ cnt -ge 1 ]
  do
     echo $str1 $str2 $i
     cnt=$(($cnt - 1))
     i=$(($i + 1))
  done
done < datafile
exit 0

# 3  
Old 03-21-2006
using array

hi

I understan the above looop. i m new for unix.
i want to do same problem by using array or by using dynamic array.
like it will enter A...z and number 1..
like for A - 5
B- 8
C - 10
D- 5
and so on
I dont know hot to use array in unix?

Best Regards,
Swapneel
Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question