Help! Need "File exist check" and line count | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Go Back    


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

Help! Need "File exist check" and line count

UNIX for Dummies Questions & Answers


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 10-23-2012
ronan1219 ronan1219 is offline
Registered User
 
Join Date: Oct 2012
Last Activity: 6 December 2012, 11:00 PM EST
Posts: 5
Thanks: 3
Thanked 0 Times in 0 Posts
Help! Need "File exist check" and line count

Hello,

I've been stuck with this for a few days now , so I'm hoping someone out there might be kind enough to help me.

I need to do a "file exist" check with a variable in the file name. After that I need to do a line count on the file, and output its results to a txt file.

For simplicity/compliance reasons, I have simplified all my paths and file names. Also the txt file has already been created, hence the ">>" instead of ">"

Right now I'm getting a "bad substitute" error for the first line "if [ -f "/path/File_${CUR_DATE).rtf" ]; then" in the code below.



Code:

Code:
#!/bin/ksh
 
HOMEDIR= "/mypath"
YEST_DATE=$(TZ=EST+24 date +%Y%m%d)
CUR_DATE=$(date "+%Y%m%d")
 
if [ -f "/path/File_${CUR_DATE).rtf" ]; then
     echo "file found with today's date" >> $HOMEDIR/file.txt
     echo " " >> $HOMEDIR/file.txt
     echo "Records in file:" >> $HOMEDIR/file.txt
     echo wc -l < "/path/File_${CUR_DATE)" >> $HOMEDIR/file.txt
elif [ -f "/path/File_${YEST_DATE).rtf" ]; then
     echo "file found with yesterday's date" >> $HOMEDIR/file.txt
     echo " " >> $HOMEDIR/file.txt
     echo "Records in file:" >> $HOMEDIR/file.txt
     echo wc -l < "/path/File_${YEST_DATE).rtf" >> $HOMEDIR/file.txt
else
     echo "file not found" >> $HOMEDIR/file.txt
 
fi


Please someone grace me with their expertise, it is very much appreciated!

Best regards,

Jay

Last edited by Franklin52; 10-24-2012 at 03:55 AM.. Reason: Please use code tags for data and code samples
Sponsored Links
    #2  
Old 10-23-2012
pamu pamu is offline
Registered User
 
Join Date: Mar 2012
Last Activity: 7 November 2014, 10:50 AM EST
Posts: 1,650
Thanks: 58
Thanked 478 Times in 474 Posts
Quote:
Originally Posted by ronan1219 View Post

Right now I'm getting a "bad substitute" error for the first line "if [ -f "/path/File_${CUR_DATE).rtf" ]; then" in the code below.
See those brackets.. marked in Red..
The Following User Says Thank You to pamu For This Useful Post:
ronan1219 (10-23-2012)
Sponsored Links
    #3  
Old 10-23-2012
itkamaraj's Avatar
itkamaraj itkamaraj is offline Forum Advisor  
^Kamaraj^
 
Join Date: Apr 2010
Last Activity: 14 November 2014, 7:56 AM EST
Posts: 3,059
Thanks: 33
Thanked 659 Times in 638 Posts
can you execute your script with -x and post the output here


Code:
 #!/bin/ksh -x

---------- Post updated at 11:01 PM ---------- Previous update was at 11:01 PM ----------

as suggested by pamu, there is a mistake in the brackets.
The Following User Says Thank You to itkamaraj For This Useful Post:
ronan1219 (10-23-2012)
    #4  
Old 10-23-2012
ronan1219 ronan1219 is offline
Registered User
 
Join Date: Oct 2012
Last Activity: 6 December 2012, 11:00 PM EST
Posts: 5
Thanks: 3
Thanked 0 Times in 0 Posts
Pamu and itkamaraj- IT WORKS!

I feel so silly that such a simple error has been driving me nuts. Thanks for helping a noob out guys :-)
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
awk command to replace ";" with "|" and ""|" at diferent places in line of file shis100 Shell Programming and Scripting 7 03-16-2011 09:59 AM
AIX cp error: "A file or directory in the path does not exist" Jackson123 AIX 3 12-18-2009 04:16 AM
how to simulate "mkdir -p /home/blah1/blah2/blah3" in "c" where only /home exist platinumedge Programming 8 10-07-2009 12:26 PM
"sed" to check file size & echo " " to destination file jockey007 Shell Programming and Scripting 7 04-28-2009 03:08 AM
Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`" Lokesha UNIX for Dummies Questions & Answers 4 12-20-2007 01:52 AM



All times are GMT -4. The time now is 06:32 AM.