Problem with while loop in shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problem with while loop in shell script
# 8  
Old 07-20-2006
Please show us the last lines of your file :

Code:
cat -v R2_20060719.610.txt | tail -2

Jean-Pierre.
# 9  
Old 07-20-2006
Hi Jean-Pierre,

My actual data is as below :

Dividend EventID IssID SecID Created
DIV 170334 3085 3225 2006/06/10
DIV 7034 305 325 2006/06/10 2006/06/12
DIV 3333 30333 325 2006/06/10 2006/06/12


cat -v R2_20060719.610.txt | tail -2
when i apply ur above command i am getting below lines as output, in which header is missing :

DIV 170334 3085 3225 2006/06/10
DIV 7034 305 325 2006/06/10 2006/06/12
DIV 3333 30333 325 2006/06/10 2006/06/12


i did not understand what is this ? Smilie

Regards,
Ravi Kumar Garlapati
# 10  
Old 07-21-2006
tail -2 print the two last records of the file.
When you execute the command, there are 3 lines in the output ! Smilie

Execute the following command on your file :
Code:
od -cx R2_20060719.610.txt

# 11  
Old 07-21-2006
Below is the output i got when i execute

od -cx R2_20060719.610.txt


0000000 D i v i d e n d \t E v e n t I D
4469 7669 6465 6e64 0945 7665 6e74 4944
0000020 \t I s s I D \t S e c I D \t C r e
0949 7373 4944 0953 6563 4944 0943 7265
0000040 a t e d \t \n D I V \t 1 7 0 3 3 4
6174 6564 090a 4449 5609 3137 3033 3334
0000060 \t 3 0 8 5 \t 3 2 2 5 \t 2 0 0 6 /
0933 3038 3509 3332 3235 0932 3030 362f
0000100 0 6 / 1 0 \t \n D I V \t 7 0 3 4 \t
3036 2f31 3009 0a44 4956 0937 3033 3409
0000120 3 0 5 \t 3 2 5 \t 2 0 0 6 / 0 6 /
3330 3509 3332 3509 3230 3036 2f30 362f
0000140 1 0 \t 2 0 0 6 / 0 6 / 1 2 \t \n D
3130 0932 3030 362f 3036 2f31 3209 0a44
0000160 I V \t 3 3 3 3 \t 3 0 3 3 3 \t 3 2
4956 0933 3333 3309 3330 3333 3309 3332
0000200 5 \t 2 0 0 6 / 0 6 / 1 0 \t 2 0 0
3509 3230 3036 2f30 362f 3130 0932 3030
0000220 6 / 0 6 / 1 2 \t A \n A \n
362f 3036 2f31 3209 410a 410a
0000234


Regards,
Ravi Kumar Garlapati
# 12  
Old 07-21-2006
Hi All,

Surprisingly my program is working fine now,
it's printing me all the lines of data file.

I did not do any thing to my data file and in script as well.
i thought of testing my luck once, suddenly it started working fine.

i dont understand what was the problem previously. Smilie
i dont understand how it's working now, with out doing anything in either of them(data and program) Smilie

full of confusions, but on the whole it's a nice experience to a fresher to Shell Scripting.

I thank all the people who responded me.
Thaking you all once again. Smilie

Regards,
Ravi Kumar Garlapati
# 13  
Old 07-21-2006
cat -v R2_20060719.610.txt | tail -2
command should have return exactly 2 lines from the file.....can you recreate the file and try......

Last edited by Dhruva; 07-21-2006 at 11:29 AM.. Reason: corrected return line
# 14  
Old 07-21-2006
Hi Dhruva,

now i am getting below 2 lines,

ndafedt1:fed_cntl $ cat -v R2_20060719.610.188 | tail -2
DIV 7034 305 325 2006/06/10 2006/06/12
DIV 3333 30333 325 2006/06/10 2006/06/12

Regards,
Ravi Kumar Garlapati
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bourne Shell - Problem with while loop variable scope.

Hello I am having issues with a script I'm working on developing on a Solaris machine. The script is intended to find out how many times a particular user (by given userid) has logged into the local system for more than one hour today. Here is my while loop: last $user | grep -v 'sshd'... (7 Replies)
Discussion started by: DaveRich
7 Replies

2. UNIX for Dummies Questions & Answers

C shell loop problem occur

Hi all, i create 2 file Config path1 5 group1 path2 6 group2 path3 10 group1 path4 15 group2 Confine group1 andrew group2 alan In my C shell script i write like this: set line_array = (`cat $app_dir/config`) set line_array_2 =... (0 Replies)
Discussion started by: proghack
0 Replies

3. Shell Programming and Scripting

loop problem in c shell

Hi all, i got problem with this statement. I use 2 time loop while in 1 statement . But it excetu at second loop while. I want it continue loop until it stop when wrong. Plz help me -- #!/bin/csh set app_dir = "/ebsxe/ebs25/users/mmlim/assignment01" set line_array = (`cat... (0 Replies)
Discussion started by: proghack
0 Replies

4. Shell Programming and Scripting

while loop problem in c shell script

Hi all, i write a script c shell set i = 1 while ( $i <= $#array ) echo "$array" @ i++ end i want to set it to i = i +2 in that statement . Can anybody help me? ---------- Post updated at 02:46 PM ---------- Previous update was at 02:35 PM ---------- anybody not how to solve it??? (2 Replies)
Discussion started by: proghack
2 Replies

5. Shell Programming and Scripting

problem with while loop in BASH shell

I have file named script1 as follows: #!/bin/bash count="0" echo "hello" echo "$count" while do echo "$count" count=`expr $count + 1` done ----------- when I run it, I get ./script1: line 9: syntax error near unexpected token `done' ./script1: line 9: `done' I... (6 Replies)
Discussion started by: npatwardhan
6 Replies

6. Shell Programming and Scripting

problem in while loop in a script

i have a script that will read each line and then grep a particular pattern and do some_stuff. Below the script while read j do q1=0 q1=`$j | grep 'INFO - LPBatch:' | wc -l` if then $j | tr -s " " | cut -d " " -f8,42,43 >> nav1.txt fi q2=0 q2=`$j | grep 'INFO - Number of Intervals... (12 Replies)
Discussion started by: ali560045
12 Replies

7. Shell Programming and Scripting

if loop problem in bourne shell

how to use if-loop in bourne shell with multiple conditions like follows if then commands fi it gives me an error test: ] missing then i put if ] it gives me an error [[ not found kindly i need the syntex for the bourne shell (5 Replies)
Discussion started by: ahmad.diab
5 Replies

8. Solaris

Problem in for loop of shell scripting in solaris

Hi below is my script for((i=0;i<=$TOTAL;i++)) do echo "IP's created are $s1.$s2.$s3.$s4" s4=`expr $s4 + 1` done where s1,2,3,4 are input varibles below error occurs while running the script syntax error at lin 11: '(' unexpected ... (12 Replies)
Discussion started by: krevathi1912
12 Replies

9. Shell Programming and Scripting

for loop problem in K shell

I want to echo from 1 to 100 using a for loop. I was trying out all possible syntax using for loop, but it errors out. can you help me in doing this? I was using for i in 1..100 do echo $i done Regards Asutoshch (4 Replies)
Discussion started by: asutoshch
4 Replies

10. Shell Programming and Scripting

Shell Script loop problem

I am writing a shell script that simulates the `wc -w` command without actually using wc itself. My problem is that the script will only read the first line of the file and just keep looping through it. I have tried both while and for loops and got the same result. Can anyone help? ... (1 Reply)
Discussion started by: MaxMouse
1 Replies
Login or Register to Ask a Question