|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 !! |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Help! Need "File exist check" and line count
Hello, I've been stuck with this for a few days now 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
fiPlease someone grace me with their expertise, it is very much appreciated! Best regards, Jay Last edited by Franklin52; 10-24-2012 at 02:55 AM.. Reason: Please use code tags for data and code samples |
| Sponsored Links | ||
|
|
#3
|
||||
|
||||
|
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
|
|||
|
|||
|
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 | ||
|
![]() |
| Thread Tools | Search this Thread |
| 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 08:59 AM |
| AIX cp error: "A file or directory in the path does not exist" | Jackson123 | AIX | 3 | 12-18-2009 03:16 AM |
| how to simulate "mkdir -p /home/blah1/blah2/blah3" in "c" where only /home exist | platinumedge | Programming | 8 | 10-07-2009 11:26 AM |
| "sed" to check file size & echo " " to destination file | jockey007 | Shell Programming and Scripting | 7 | 04-28-2009 02:08 AM |
| Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`" | Lokesha | UNIX for Dummies Questions & Answers | 4 | 12-20-2007 12:52 AM |
|
|