Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Help! Need "File exist check" and line count Post 302720123 by ronan1219 on Tuesday 23rd of October 2012 01:26:19 PM
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
 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
CHECK-ZONE-EXPIRATION(1p)				User Contributed Perl Documentation				 CHECK-ZONE-EXPIRATION(1p)

NAME
check-zone-expiration SYNOPSIS
# check-zone-expiration dnssec-tools.org paypal.com dnssec-tools.org will expire in 26 days, 2 hours, 16 minutes, 36 seconds paypal.com will expire in 12 days, 17 hours, 7 minutes, 1 second # check-zone-expiration -m 1123200 dnssec-tools.org paypal.com paypal.com will expire in 12 days, 17 hours, 6 minutes, 22 seconds DESCRIPTION
The check-zone-exiration script reports how long until a zone will expire by querying for the zone's (top level) RRSIG and calculating how much time is left before the signatures will no longer be valid. It will then report how much time is left in human readable form. If the -m switch is provided with a time argument (in seconds), it will only print output for zones that have less than that time left. OPTIONS
-m STRING --minimum-reporting=STRING Minimum reporting time, or else be silent for the zone COPYRIGHT
Copyright 2012-2012 SPARTA, Inc. All rights reserved. See the COPYING file included with the DNSSEC-Tools package for details. AUTHOR
Wes Hardaker, hardaker@tislabs.com SEE ALSO
donuts(1) perl v5.14.2 2012-05-07 CHECK-ZONE-EXPIRATION(1p)
All times are GMT -4. The time now is 10:03 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy