Trying to print data row/columnwise


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Trying to print data row/columnwise
# 1  
Old 02-18-2009
Trying to print data row/columnwise

PRDCNT=12
FILS=
f1=1
f2=2
f3=3
f4=4
f5=5
CNT=0
CNT=`expr $PRDCNT - 5`
MNT=6
VR=1
while [ $MNT -le $PRDCNT ]
do
f$VR="$f$VR,$MNT"
echo "$f$VR"
MNT=`expr $MNT + 1`
CNT=`expr $CNT - 1`
VR=`expr $VR + 1`
if [ $VR -gt 5 ]
then
VR=1
fi
done

getting the following error
swa.sh: f1=1,6: not found
1
swa.sh: f2=2,7: not found
2
swa.sh: f3=3,8: not found
3
swa.sh: f4=4,9: not found
4
swa.sh: f5=5,10: not found
5
1 2 3 4 5
swa.sh: f1=1,11: not found
1
swa.sh: f2=2,12: not found
2
swa.sh: f3=3,13: not found
3
swa.sh: f4=4,14: not found
4
swa.sh: f5=5,15: not found
5
1 2 3 4 5

could some one please help
# 2  
Old 02-18-2009
first part . . . . you're trying to assign values to variables named f1, f2, f3.

In order to do that, you must use "eval" before each of those statements:

ie:
Code:
eval f$VR="$f$VR,$MNT"

next, for efficiency's sake, use this instead of expr:

Code:
var=$(( var + 1 ))

... or similar math type statements.
# 3  
Old 02-18-2009
Thanks for the reply.
this is the output I am getting
sh swa.sh
1,6 2,7 3,8 4,9 5,10
1,11 2,12 3,13 4,14 5,15

But I expect the output to be 1,6,11 2,7,12 3,8,13 4,9,14 5,10,15
# 4  
Old 02-18-2009
Please post the revised code. When I made my recommended changes to your script, i got much different results.
# 5  
Old 02-18-2009
PRDCNT=15
FILS=
f1="1"
f2="2"
f3="3"
f4="4"
f5="5"
CNT=0
CNT=`expr $PRDCNT - 5`
echo $CNT
MNT="6"
VR=1
while [ $MNT -le $PRDCNT ]
#while [ $CNT -gt 0 ]
do
# f$VR="$f$VR $MNT"
eval f$VR="$f$VR,$MNT"
# echo "$f$VR"
MNT=`expr $MNT + 1`
CNT=`expr $CNT - 1`
VR=`expr $VR + 1`
if [ $VR -gt 5 ]
then
echo $f1 $f2 $f3 $f4 $f5
VR=1
fi
done
# 6  
Old 02-18-2009
and as replacement for expr are they parenthesis() or curly brackets {}
# 7  
Old 02-18-2009
they are parenthesis.

You're having "eval" parsing problems. Try this:

Code:
PRDCNT=15
FILS=
f1="1"
f2="2"
f3="3"
f4="4"
f5="5"
CNT=0
CNT=`expr $PRDCNT - 5`
echo $CNT
MNT="6"
VR=1
while [ $MNT -le $PRDCNT ]
do
        eval f$VR="\$f$VR,$MNT"
        MNT=`expr $MNT + 1`
        CNT=`expr $CNT - 1`
        VR=`expr $VR + 1`
        if [ $VR -gt 5 ]
         then
                echo $f1 $f2 $f3 $f4 $f5
                VR=1
        fi
done

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Reading Xml file and print the values into the text file in columnwise?

hi guys, i want help... Reding XML file and print the values into the text file using linux shell script file as per below xml file <sequence> <Filename>aldorzum.doc</Filename> <DivisionCode>US</DivisionCode> <ContentType>Template</ContentType> <ProductCode>VIMZIM</ProductCode> </sequence>... (4 Replies)
Discussion started by: sravanreddy
4 Replies

2. Shell Programming and Scripting

Print row on 4th column to all row

Dear All, I have input : SEG901 5173 9005 5740 SEG902 5227 5284 SEG903 5284 5346 SEG904 5346 9010 SEG905 5400 5456 SEG906 5456 5511 SEG907 5511 9011 SEG908 5572 9015 SEG909 5622 9020 SEG910 5678 5739 SEG911 5739 5796 SEG912 5796 9025 ... (3 Replies)
Discussion started by: attila
3 Replies

3. Shell Programming and Scripting

Get row number from file1 and print that row of file2

Hi. How can we print those rows of file2 which are mentioned in file1. first character of file1 is a row number.. for eg file1 1:abc 3:ghi 6:pqr file2 a abc b def c ghi d jkl e mno f pqr ... (6 Replies)
Discussion started by: Abhiraj Singh
6 Replies

4. Emergency UNIX and Linux Support

[Solved] Mysql - Take data from row and copy it to another row

Sorry if I repost my question in this section, but I'm really in a hurry since I have to finish my work... :( Dear community, I have a table with two rows like: Row1 Row2 ======= ======= 7,3 text 1 1,3 text 2 1,2,3 blabla What i need to do is add/copy... (2 Replies)
Discussion started by: Lord Spectre
2 Replies

5. Shell Programming and Scripting

using perl to print columnwise

Suppose we have two files one file FAAA_HUMAN.input1 2 5 7 11 and another file FAAA_HUMAN.output M*0.0540*0.0039*0.2212*0.0082*0.0020*0.0137*0.0028*0.0029*0.2198*0.0104*0.0889*0.0282*0.0049*0.0804*0.1743*0.0215*0.0531*0.0071*0.0007*0.0021*0.7270*2.5000*... (4 Replies)
Discussion started by: cdfd123
4 Replies

6. Shell Programming and Scripting

How to insert data befor some field in a row of data depending up on values in row

Hi I need to do some thing like "find and insert before that " in a file which contains many records. This will be clear with the following example. The original data record should be some thing like this 60119827 RTMS_LOCATION_CDR INSTANT_POSITION_QUERY 1236574686123083rtmssrv7 ... (8 Replies)
Discussion started by: aemunathan
8 Replies

7. Shell Programming and Scripting

Comparing files columnwise and print the differences in third file

Hello Everybody!!!!!!!!! Request you to help me with the below mentioned issue: I have 2 files say, File 1: a|4|7 b|3|2 c|8|8 d|8|9 File 2: a|4|6 b|2|2 c|8|8 d|9|8 The third file(output file) should have: Data mismatch in row 1 column 3 Data mismatch in row 2 coumn 2 Data... (3 Replies)
Discussion started by: abhijeet1409
3 Replies

8. UNIX for Dummies Questions & Answers

Print out a row of data

hi im completely new at unix so dont hate me for asking what is probably the easiest question ever. below is an extract of some data im processing. the first column is like a counter while the second is an ip address. i need to be able to output the ip address based on which has the largest... (4 Replies)
Discussion started by: Streetrcr
4 Replies

9. Shell Programming and Scripting

rearranging the data in file (from columnwise to rowwise)

Hi I have one file which is having data like 10201 10202 10205 10206 10207 10208 10209 10210 10211 10213 10215 10801 10802 11406 11415 11422 11426 11513 11514 11515 11516 11517 11518 11519 11520 11521 11522 11523 11524 11525 11530 11604 11608 11611 11717 11718 11719 11722 11725... (3 Replies)
Discussion started by: reldb
3 Replies
Login or Register to Ask a Question