cnt=1
IFS=";"
while read a b c d; do
echo $a $b $c $d
done<datafile
My result:
1 n b c
2 n b c
3 n b c
4 n b c
5 n b c
6 n b c
7 n b c
8 n b c
9 n b c
10 n b c
My wanted-result
1 n b c list[1] row[1]
2 n b c list[1] row[2]
3 n b c list[1] row[3]
4 n b c list[1] row[4]
5 n b c list[1] row[5]
6 n b c list[2] row[1]
7 n b c list[2] row[2]
8 n b c list[2] row[3]
9 n b c list[2] row[4]
10 n b c list[2] row[5]
How can I modify my code to give me such data output? Thanks!
if you change the list after every 5 rows them try somthing like this.
In basic shell
#!/usr/bin/sh
row=1
list=1
IFS=";"
while read a b c d; do
echo "$a $b $c $d list[$list] row[$row]"
row=`expr $row + 1`
list=`expr $list + 1`
if [ $row -eq 6 ]
then
row=1
fi
if [ $list -eq 6 ]
then
list=1
fi
#!/usr/bin/sh
row=1
list=1
IFS=";"
while read a b c d; do
echo "$a $b $c $d list[$list] row[$row]"
row=`expr $row + 1`
if [ $row -eq 6 ]
then
row=1
list=`$list + 1`
fi
if [ $list -eq 6 ]
then
list=1
fi
Andrek, Thanks I change this line to make it works!
list=`$list + 1` to list=`expr $list + 1`
and I add
done<datafile
Many thanks!
#!/usr/bin/sh
row=1
list=1
IFS=";"
while read a b c d; do
echo "$a $b $c $d list[$list] row[$row]"
row=`expr $row + 1`
if [ $row -eq 6 ]
then
row=1
list=`$list + 1`
fi
if [ $list -eq 6 ]
then
list=1
fi
_______________________________________________________________
Anbu23, Thanks for the help!