Help! Need "File exist check" and line count


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Help! Need "File exist check" and line count
# 1  
Old 10-23-2012
Help! Need "File exist check" and line count

Hello,

I've been stuck with this for a few days now Smilie, 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
# 2  
Old 10-23-2012
Quote:
Originally Posted by ronan1219

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..
This User Gave Thanks to pamu For This Post:
# 3  
Old 10-23-2012
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.
This User Gave Thanks to itkamaraj For This Post:
# 4  
Old 10-23-2012
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 :-)
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

2. Shell Programming and Scripting

Failure: if grep "$Var" "$line" inside while read line loop

Hi everybody, I am new at Unix/Bourne shell scripting and with my youngest experiences, I will not become very old with it :o My code: #!/bin/sh set -e set -u export IFS= optl="Optl" LOCSTORCLI="/opt/lsi/storcli/storcli" ($LOCSTORCLI /c0 /vall show | grep RAID | cut -d " "... (5 Replies)
Discussion started by: Subsonic66
5 Replies

3. Shell Programming and Scripting

Count the pipes "|" in line and delete line if count greter then number.

Hello, I have been working on Awk/sed one liner which counts the number of occurrences of '|' in pipe separated lines of file and delete the line from files if count exceeds "17". i.e need to get records having exact 17 pipe separated fields(no more or less) currently i have below : awk... (1 Reply)
Discussion started by: ketanraut
1 Replies

4. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

5. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

6. Solaris

How to check "faulty" or "stalled" print queues - SAP systems?

Hi all, First off, sorry for a long post but I think I have no other option if I need to explain properly what I need help for. I need some advise on how best to check for "faulty" or "stalled/jammed' print queues. At the moment, I have three (3) application servers which also acts as print... (0 Replies)
Discussion started by: newbie_01
0 Replies

7. AIX

AIX cp error: "A file or directory in the path does not exist"

Hello fellow UNIX fans, I'm running AIX 4.3 and getting an error message “cp: /a/file2.db: A file or directory in the path does not exist” when I run the following command: cp /b/file.db /a/file2.db It stops every time about 95% of the way through the copy process at 1,073,741,312 bits. ... (3 Replies)
Discussion started by: Jackson123
3 Replies

8. Programming

how to simulate "mkdir -p /home/blah1/blah2/blah3" in "c" where only /home exist

I'm trying to make use of mkdir(char *pathname, S_IRWXU) to create the directories. but it only creates one directory at a time. so I have to separate the tokens for "/home/blah1/blah2/blah3" as "home blah1 blah2 blah3" using delimiter "/", but it is again hectic to create such directory... (8 Replies)
Discussion started by: platinumedge
8 Replies

9. Shell Programming and Scripting

"sed" to check file size & echo " " to destination file

Hi, I've modified the syslogd source to include a thread that will keep track of a timer(or a timer thread). My intention is to check the file size of /var/log/messages in every one minute & if the size is more than 128KB, do a echo " " > /var/log/messages, so that the file size will be set... (7 Replies)
Discussion started by: jockey007
7 Replies

10. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies
Login or Register to Ask a Question