UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
  #1  
Old July 15th, 2004, 03:15 PM
mquadri mquadri is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 5 mquadri User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
While loop stuck

To give a short description what i am doing in the script is reading from a regular text file for the directory structure and changing it to another format and creating the structure, but the problem is once it reads a line from the text file it fails on the second line, I am stuck with the while loop any suggestions please.
Thanks

The REQFILE has
/RIP/module/resources/com/res/app/email/htmlConfirmationEmailHP.txt
RIP/module/resources/com/crm/client/UserMessages.properties
RIP/module/config/html/BrandDetectorServlet.properties


Script:
#!/bin/ksh
STAGEDIR=/home/user/Patch/build_patch/lists
SCRIPTDIR=/home/user/Patch

REQFILE=rip_files.txt
START=(What should I put)
END=`cat $REQFILE|wc -l`
echo $END
while [ $START -lt $END ]
do
for FLPATHNM in `cat $REQFILE`
do
cd $STAGEDIR

FSTCHR=`echo $FLPATHNM|awk '{print substr($0,1,1)}'`
LSTCHR=`echo $FLPATHNM|awk '{print substr($0,length($0),1)}'`
if [ $FSTCHR = "/" ]
then FLPATHNM1=`echo $FLPATHNM|awk '{print substr($0,2,length($0))}'`
else FLPATHNM1=`echo $FLPATHNM`
fi
if [ $LSTCHR = "/" ]
then TFLPATHNM2=`echo $FLPATHNM1|awk '{print substr($0,1,length($0)-1)}'`
else TFLPATHNM2=`echo $FLPATHNM1`

fi
TFLPATHNM4=`echo $TFLPATHNM2|sed 's/RIP\/module\/resources/temp\/RIP\/lib\/resourcepatches/'`
TFLPATHNM4=`echo $TFLPATHNM2|sed 's/RIP\/module\/config/temp\/RIP\/lib\/configpatches/'`

FLPATHNM2=$TFLPATHNM4
LENPATH=`echo $FLPATHNM2|awk '{print length()}'`
SLSHFLG=0
SLSHPOS=X
while [ $SLSHFLG -ne 1 ] && [ $LENPATH -gt 0 ]
do
CHRLKCMP=`echo $FLPATHNM2|awk '{print substr($0,'$LENPATH',1)}'`
if [ $CHRLKCMP = "/" ]
then SLSHFLG=1
SLSHPOS=$LENPATH
fi
((LENPATH = LENPATH - 1))
done
((SLSHPOS = SLSHPOS + 1))
CDPATH=`echo $FILENM|awk '{print substr($0,1,'$LENPATH')}'`
FILENM=`echo $FILENM|awk '{print substr($0,'$SLSHPOS',length())}'`
FSTCHR=`echo $FLPATHNM2|awk '{print substr($0,1,1)}'`
if [ $FSTCHR = "/" ]
then FILENM=`echo $FLPATHNM2|awk '{print substr($0,2)}'`
else FILENM=$FLPATHNM2
fi
LENPATH=`echo $FILENM|awk '{print length()}'`
SLSHFLG=0
SLSHPOS=X
while [ $SLSHFLG -ne 1 ] && [ $LENPATH -gt 0 ]
do
CHRLKCMP=`echo $FILENM|awk '{print substr($0,'$LENPATH',1)}'`
if [ $CHRLKCMP = "/" ]
then SLSHFLG=1
SLSHPOS=$LENPATH
fi
((LENPATH = LENPATH - 1))
done
if [ $SLSHPOS = X ]
then echo "ERROR: "$FILENM": Path Specified Is Incorrect!"
continue
fi
((SLSHPOS = SLSHPOS + 1))
cd /home/user/Patch
CDPATH=`echo $FILENM|awk '{print substr($0,1,'$LENPATH')}'`
echo $CDPATH
FILENM=`echo $FILENM|awk '{print substr($0,'$SLSHPOS',length())}'`
if [ -a $SCRIPTDIR/$CDPATH ]
then cd $SCRIPTDIR/$CDPATH
cp $MODULEDIR/$TFLPATHNM2 $SCRIPTDIR/$CDPATH
else mkdir -p $CDPATH
cp $MODULEDIR/$TFLPATHNM2 $SCRIPTDIR/$CDPATH
continue
fi
echo "-> File: "$FILENM
done
done(end while loop)

Reply With Quote
  #2  
Old July 15th, 2004, 04:05 PM
jim mcnamara jim mcnamara is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jun 2004
Posts: 1,299 jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 8 h 41 m 52 sec
Reputation Power: 47
Please use code tags. Based on what I think I can read.
Code:
REQFILE=rip_files.txt
START=1
# you are not decrementing END
END=`cat $REQFILE|wc -l`
......

let END=$END-1
done



Plus, do you really do need the second (inner) loop? You are reading all records in REQFILE in this inner loop as well.
Code:
for FLPATHNM in `cat $REQFILE`
do
   .....
done 


In " pseudocode" this is what you are doing
Code:
for lines in rip_file.txt
   for lines in rip_file.txt
      play with the file
   end loop
end loop

Reply With Quote
  #3  
Old July 15th, 2004, 05:13 PM
mquadri mquadri is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 5 mquadri User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Stuck

I tried using

while read LINE
but it doesnot works
I need to read each line from the REQFILE
but the while loop does not so i have to do for FL `cat in REQFILE`
I have been stuck in this thing for hours
Thanks for the right suggestion about END
Thanks

Reply With Quote
  #4  
Old July 16th, 2004, 09:48 AM
jim mcnamara jim mcnamara is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jun 2004
Posts: 1,299 jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 8 h 41 m 52 sec
Reputation Power: 47
Code:
while read line
do 
      echo $line
     # mess with data here
done < /path/to/file_to_read

This while loop reads text files.

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > While loop stuck


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway