|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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) |
|
#2
|
|||
|
|||
|
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
|
|
#3
|
|||
|
|||
|
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 |
|
#4
|
|||
|
|||
|
Code:
while read line
do
echo $line
# mess with data here
done < /path/to/file_to_read
This while loop reads text files. |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > While loop stuck |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|