Please help this syntax error !!!


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Please help this syntax error !!!
# 1  
Old 02-11-2015
Please help this syntax error !!!

Please help with this syntax.....somehow not able make it work....
Code:
 
 
/export/home/mytmp/abc> ls -ltr
total 9
-rw-r--r--   1 ca7prod  ftpusers    1230 Feb  7 10:42 test_abc.dat
-rw-r--r--   1 ca7prod  ftpusers    1230 Feb  7 20:31 test1_abc.dat
-rw-r--r--   1 ca7prod  ftpusers    1230 Feb 11 09:06 test2_abc.dat


Code:
 
#!/bin/ksh -x
cd /export/home/mytmp/abc
OUTFILE="/export/home/mytmp/Readme_File.txt"
FILE=`ls | awk -F. '{print $NF}'`
case "$FILE" in
        "gz" )
echo "###########################TEST###############################" >> $OUTFILE
echo "Contained with this README.TXT file are all of the file specs " >> $OUTFILE
echo "###########################TEST###############################" >> $OUTFILE
printf '%s\n' >> $OUTFILE
for i in *gz ;
do
echo "Filename         : $i" >> $OUTFILE
echo " Compression     : GZIP" >> $OUTFILE
echo " GZIP Bytes      : `gunzip -l $i |tail -1 | awk '{print $1}'`" >> $OUTFILE
echo " Unzipped Bytes  : `gunzip -l $i |tail -1 | awk '{print $2}'`" >> $OUTFILE
echo " Records         : `gzcat $i | wc -l | awk '{print $1}'`" >> $OUTFILE
printf '%s\n' >> $OUTFILE
done
        ;;
        dat )
echo "###########################TEST###############################" >> $OUTFILE
echo "Contained with this README.TXT file are all of the file specs " >> $OUTFILE
echo "###########################TEST###############################" >> $OUTFILE
printf '%s\n' >> $OUTFILE
for i in *.dat ;
do
echo "Filename         : $i" >> $OUTFILE
echo " Compression     : NONE" >> $OUTFILE
echo " Total Bytes     : `ls -l $i | awk '{print $5}'`" >> $OUTFILE
echo " Records         : `wc -l $i | awk '{print $1}'`" >> $OUTFILE
printf '%s\n' >> $OUTFILE
done
        ;;
        *)         do nothing 
 ;;
esac

This is output:

Code:
 
"###########################TEST###############################"
"Contained with this README.TXT file are all of the file specs "
"###########################TEST###############################"
 
Filename         : test1_abc.dat
 Compression     : NONE
 Total Bytes     : 1230
 Records         : 15
 Record Length   : 80
 
Filename         : test2_abc.dat
 Compression     : NONE
 Total Bytes     : 1230
 Records         : 15
 Record Length   : 80
 
Filename         : test_abc.dat
 Compression     : NONE
 Total Bytes     : 1230
 Records         : 15
 Record Length   : 80


Last edited by dotran; 02-11-2015 at 12:26 PM..
# 2  
Old 02-11-2015
Hi,
Your FILE variable contains several time dat but you don't loop for the case.
a correct code will:
Code:
FILES=`ls | awk -F. '{print $NF}'`
for FILE in $FILES
do
case "$FILE" in
...
...
done

Regards.
# 3  
Old 02-11-2015
Apart from some hints on improvements e.g. performance, maintenance and readability, I can't figure your problem. What do you want to achieve other than the output that you have got?
# 4  
Old 02-11-2015
The use of awk for splitting the file name seems a little heavyweight. If you have hundreds of files, this will slow you down. You be better to use Korn shell's on variable substitution commands. These are done in the current shell so there are costs with creating a new process each time you loop like this:-
Code:
for file in `ls -1`         # Avoiding for file in *  in case the expansion exceeds maximum line length
do
   lastbit="${file##*.}"    # Throw away everything before and including the last full-stop
   whatever .....
done

.... or if your logic needs you to determine all the last bits (I'm not going to call them file types or extensions as Unix doesn't care) you could more simply:-
Code:
for LAST_BIT in `ls -1 | cut -f2 -d"." | sort -u`
do
   whatever.......
done


i must admit that I'm struggling to find where you generate the output Record Length : anywhere, or is this your desired output rather than what you are getting. If there is a syntax error, I don't see it. Do you mean a logic error perhaps?


Can you write your logic in simple English with bullet points (LIST tags) for clarity? You can indent the list by setting up nested LISTs like this:-
Quote:
[LIST][*]First line
[*]Second line
[LIST]
[*]Indented line1
[*]Indented line2
[/LIST][*]Third line
[/LIST]
... which generates this:-
  • First line
  • Second line
    • Indented line1
    • Indented line2
  • Third line
I'm afraid i just don't quite see what you are getting at/stuck with.



Robin
# 5  
Old 02-11-2015
Not really sure what's wrong and not get output on the case....


Code:
/export/home/mytmp/abc> ls -ltr
total 9
-rw-r--r--   1 ca7prod  ftpusers    1230 Feb  7 10:42 test_abc.dat
-rw-r--r--   1 ca7prod  ftpusers    1230 Feb  7 20:31 test1_abc.dat
-rw-r--r--   1 ca7prod  ftpusers    1230 Feb 11 09:06 test2_abc.dat

Code:
 
#!/bin/ksh -x
cd /export/home/mytmp/abc
OUTFILE="/export/home/mytmp/Readme_File.txt"
echo "###########################TEST###############################" >> $OUTFILE
echo "Contained with this README.TXT file are all of the file specs " >> $OUTFILE
echo "###########################TEST###############################" >> $OUTFILE
printf '%s\n' >> $OUTFILE
for FILES in *
do
LETTER=`ls | awk -F. '{print $NF}'`
        case "$LETTER" in
        "gz" )
echo "Filename         : $FILE" >> $OUTFILE
echo " Compression     : GZIP" >> $OUTFILE
echo " GZIP Bytes      : `gunzip -l $FILE |tail -1 | awk '{print $1}'`" >> $OUTFILE
echo " Unzipped Bytes  : `gunzip -l $FILE |tail -1 | awk '{print $2}'`" >> $OUTFILE
echo " Records         : `gzcat $FILE | wc -l | awk '{print $1}'`" >> $OUTFILE
printf '%s\n' >> $OUTFILE
        ;;
        "dat" )
echo "Filename         : $FILE" >> $OUTFILE
echo " Compression     : NONE" >> $OUTFILE
echo " Total Bytes     : `ls -l $FILE | awk '{print $5}'`" >> $OUTFILE
echo " Records         : `wc -l $FILE | awk '{print $1}'`" >> $OUTFILE
printf '%s\n' >> $OUTFILE
        ;;
        #* )
        #echo "do nothing."
        #;;
        esac
done

Code:
./read.ksh
+ cd /export/home/mytmp/abc
+ OUTFILE=/export/home/mytmp/Readme_File.txt
+ echo ###########################TEST###############################
+ 1>> /export/home/mytmp/Readme_File.txt
+ echo Contained with this README.TXT file are all of the file specs 
+ 1>> /export/home/mytmp/Readme_File.txt
+ echo ###########################TEST###############################
+ 1>> /export/home/mytmp/Readme_File.txt
+ printf %s\n
+ 1>> /export/home/mytmp/Readme_File.txt
+ + awk -F. {print $NF}
+ ls
LETTER=dat
dat
dat
+ + awk -F. {print $NF}
+ ls
LETTER=dat
dat
dat
+ + awk -F. {print $NF}
+ ls
LETTER=dat
dat
dat

# 6  
Old 02-11-2015
Not a single iota clearer than before. What's your request?
# 7  
Old 02-11-2015
Thanks everyone....now i figure what's wrong. Thanks all again !!!

Code:
 
#!/bin/ksh -x
cd /export/home/mytmp/abc
OUTFILE="/export/home/mytmp/Readme_File.txt"
echo "###########################TEST###############################" >> $OUTFILE
echo "Contained with this README.TXT file are all of the file specs " >> $OUTFILE
echo "###########################TEST###############################" >> $OUTFILE
printf '%s\n' >> $OUTFILE
for FILE in *
do
LETTER=`ls | awk -F. '{print $NF}' |sort -u`
        case "$LETTER" in
        "gz" )
echo "Filename         : $FILE" >> $OUTFILE
echo " Compression     : GZIP" >> $OUTFILE
echo " GZIP Bytes      : `gunzip -l $FILE |tail -1 | awk '{print $1}'`" >> $OUTFILE
echo " Unzipped Bytes  : `gunzip -l $FILE |tail -1 | awk '{print $2}'`" >> $OUTFILE
echo " Records         : `gzcat $FILE | wc -l | awk '{print $1}'`" >> $OUTFILE
printf '%s\n' >> $OUTFILE
        ;;
        "dat" )
echo "Filename         : $FILE" >> $OUTFILE
echo " Compression     : NONE" >> $OUTFILE
echo " Total Bytes     : `ls -l $FILE | awk '{print $5}'`" >> $OUTFILE
echo " Records         : `wc -l $FILE | awk '{print $1}'`" >> $OUTFILE
printf '%s\n' >> $OUTFILE
        ;;
        * )
        echo "do nothing."
        exit 10
        ;;
        esac
done



Output:
Code:
 
cat Readme_File.txt
###########################TEST###############################
Contained with this README.TXT file are all of the file specs 
###########################TEST###############################
 
Filename         : test1_DEF.txt.gz
 Compression     : GZIP
 GZIP Bytes      : 238
 Unzipped Bytes  : 1230
 Records         : 15
 
Filename         : test_DEF.txt.gz
 Compression     : GZIP
 GZIP Bytes      : 238
 Unzipped Bytes  : 1230
 Records         : 15

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Getting this error syntax error near unexpected token `)'

Hi Everyone, my script was running Ok, but suddenly it started giving this error. ./update_env_bi.sh: line 54: syntax error near unexpected token `)' ./update_env_bi.sh: line 54: `sed -i "s/PORT=*1/PORT=$2/" repository.xml' The line 54 has this code. sed -i "s/PORT=*1/PORT=$2/"... (2 Replies)
Discussion started by: shajay12
2 Replies

2. Shell Programming and Scripting

IF section problem. syntax error: unexpected end of file error

Hello, I have another problem with my script. Please accept my apologies, but I am really nooby in sh scripts. I am writing it for first time. My script: returned=`tail -50 SapLogs.log | grep -i "Error"` echo $returned if ; then echo "There is no errors in the logs" fi And after... (10 Replies)
Discussion started by: jedzio
10 Replies

3. Linux

Ambiguous redirect error and syntax error when using on multiple files

Hi, I need help on following linux bash script. When I linux commands for loop or while loop on individual file it runs great. but now I want the script to run on N number of files so it gives me ambiguous redirect error on line 12 and syntax error on line 22 : (pls help ); #!/bin/bash #... (16 Replies)
Discussion started by: Madhusudan Das
16 Replies

4. Shell Programming and Scripting

Receiving error: ./ang.ksh[35]: 0403-057 Syntax error at line 116 : `done' is not expected.

Hi All I am quite new to Unix. Following is a shell script that i have written and getting the subject mentioned error. #!/bin/ksh #------------------------------------------------------------------------- # File: ang_stdnld.ksh # # Desc: UNIX shell script to extract Store information.... (3 Replies)
Discussion started by: amitsinha
3 Replies

5. Shell Programming and Scripting

ERROR: ./launch_full_backup.sh[18]: Syntax error at line 28 : `else' is not expected.

Help please! :confused: I have the following error with the following file and the emails are not arriving to the email, any idea please? ERROR: ./launch_full_backup.sh: Syntax error at line 28 : `else' is not expected. FECHA=`date +%d%m%y%H%M`... (2 Replies)
Discussion started by: villenan
2 Replies

6. Programming

Newbie Question.. -> error: syntax error before ';' token

Hello, the following is generating a error at the line "tmprintf(&tmBundle, _TMC("{0}"),Prompt);"... a bit lost as I am diving into this debug... Thank you in advance... int H_YesNo(TMCHAR *Prompt, int DefVal) { TMCHAR YesNo = '\0'; tmprintf(&tmBundle, _TMC("{0}"),Prompt); while... (3 Replies)
Discussion started by: reelflytime
3 Replies

7. Shell Programming and Scripting

sed error : Syntax error: redirection unexpected

My script is throwing the error 'Syntax error: redirection unexpected' My line of code.. cat nsstatustest.html | sed s/<tr><td align="left">/<tr><td align="left" bgcolor="#000000"><font color="white">/ > ztmp.Ps23zp2s.2-Fpps3-wmmm0dss3 HTML tags are getting in the way but they're needed to... (3 Replies)
Discussion started by: phpfreak
3 Replies

8. AIX

nim mksysb error :/usr/bin/savevg[33]: 1016,07: syntax error

-------------------------------------------------------------------------------- Hello, help me please. I am trying to create a mksysb bakup using nim. I am geting this error, how to correct it ? : Command : failed stdout: yes stderr: no... (9 Replies)
Discussion started by: astjen
9 Replies

9. UNIX for Dummies Questions & Answers

awk Shell Script error : "Syntax Error : `Split' unexpected

hi there i write one awk script file in shell programing the code is related to dd/mm/yy to month, day year format but i get an error please can anybody help me out in this problem ?????? i give my code here including error awk ` # date-month -- convert mm/dd/yy to month day,... (2 Replies)
Discussion started by: Herry
2 Replies
Login or Register to Ask a Question