Sponsored Content
Top Forums Shell Programming and Scripting Check file exists from a shellscript Post 302309937 by lavascript on Thursday 23rd of April 2009 09:23:23 AM
Old 04-23-2009
Code:
foundc=0
nfoundc=0
fflist=""
nflist=""

for file in $FILELIST
do
   if [[ -s "${file}" ]];then
       # file is found and is > 0 bytes.
       foundc=$(( found + 1 ))
       fflist="${fflist}\n${file}"
       ...do something else you want...
   else
       # file is not found or is 0 bytes
       nfoundc=$(( nfounc + 1 ))
       nflist="${nflist}\n${file}"
       ...do something else you want...
   fi
done

print "List of found files:\n\n${fflist}\n---------"
print "List of NOT found files:\n\n${nflist}\n-----"

print "number of files in [$FILELIST] found = [${foundc}]\n"
print "number of files in [$FILELIST] NOT found = [${nfoundc}]\n"

I've not tested above so maybe couple of bugs.

You could of course save the outputs to a file instead of a variable.

NOTE: accessing the variable list of files will contain \n whereas printing it out should put each entry on new line.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

check if remote file exists

Hi Does anybody know how I can check if a file exists on a remote machine i.e. see bellow, this doesn't work by the way and if tried countless variations on this #!/bin/sh hostname=server56 if ; then echo file exists else echo file doesn't exist fi Any help on this would... (2 Replies)
Discussion started by: hcclnoodles
2 Replies

2. Programming

Check if file exists + ulp :S

Hi all! I know that this may not be the best forum to ask ulp and eagle related question. But the guys from eagle didn't know the answer and this is the BEST programming forum I know :D How can I check if a file exists while programming eagle's ulp's? There is not much information on-line.... (2 Replies)
Discussion started by: ruben.rodrigues
2 Replies

3. Shell Programming and Scripting

Script to check if file exists

guys, I am trying to write a script that does the following: it looks for a file in a specific directory and if the file is not there (NOT), it emails me. I have tried the following but its not working. It simply hangs up. Please help. if then mail -s 'blah blah blah' my email... (4 Replies)
Discussion started by: basisvasis
4 Replies

4. Shell Programming and Scripting

Check to see if a file exists?

Hi. I'd like to have an IF-Then-Else statement where I can check to see if a file exists? We have the Bourne Shell by default. I'm looking for the syntax to do something like this: if myfile.txt exists then ...my code else ...my code end if Any help would be greatly... (5 Replies)
Discussion started by: buechler66
5 Replies

5. Shell Programming and Scripting

how to check to see if a file exists?

I want to write a script to see if various files exist. What I want to do is have the script search in various directories if a file exist, and if not, then output something like "/path/file does not exist". I don't actually know of how to check and see if a file exists or not. What I have in mind... (2 Replies)
Discussion started by: astropi
2 Replies

6. Shell Programming and Scripting

File exists, but cannot be opened.How to check- whether it could be opened to read when it exists

Hi #Testing for file existence if ; then echo 'SCHOOL data is available for processing' else echo 'SCHOOL DATA IS NOT AVAILABLE FOR PROCESSING' : i wrote a script, where it begins by checking if file exists or not. If it exists, it truncates the database... (2 Replies)
Discussion started by: rxg
2 Replies

7. Shell Programming and Scripting

How to check if the file exists in directory?

Hi Gurus, I have a requests to find if all the file in the filelist exist in certain directory. example: my filelist abc def ddd cde afg how can I find these 5 files exists at director /home/abc Thanks in advance (7 Replies)
Discussion started by: ken6503
7 Replies

8. Shell Programming and Scripting

Check if file exists or not

Hi, I want to check if the file exists or not in the directory. i am trying below code but not working. File="/home/va59657/Account_20090213*.dat" echo "$File" if ]; then echo "file found" else echo "file not found" fi However i am getting file not found even if file exits as... (5 Replies)
Discussion started by: Vivekit82
5 Replies

9. Shell Programming and Scripting

To check if file exists

Hi, I have the below code written. However I am not getting the desired output I am checking if the particular path has file in it. #!/bin/bash ls -l /IRS2/IRS2_ODI/INFILE/*LS* 1>/dev/null 2>/dev/null if then echo $? echo "File Exists" fi ... (3 Replies)
Discussion started by: Shanmugapriya D
3 Replies

10. UNIX for Beginners Questions & Answers

Check if file exists

I need to check whether a file exists and has been changed. The file should contain a specific string. The file should also have been changed within the last ten seconds. How do I do that? (3 Replies)
Discussion started by: locoroco
3 Replies
findmsg(1)						      General Commands Manual							findmsg(1)

NAME
findmsg, dumpmsg - create message catalog file for modification SYNOPSIS
sym] sym]] file ... file ... DESCRIPTION
The command extracts messages from a C program source file and writes them to the standard output in a format suitable for input to (see gencat(1)). The input file will be preprocessed using (see cpp(1)) in order to select print specifiers and handle conditional primitives. If multiple input files are specified and the option is not used, the files are processed sequentially such that message catalog comment lines identifying the input file are written before the output for each input file. The command scans the source files for uncommented lines with one of the following three formats embedded within it: or any combination of these formats wholly contained on a single physical line. could be a string constant or a combination of string con- stants and print specifiers (PRI*). Any number of spaces or tabs can separate the comment from the message. The digit n, which can be any valid message number (see gencat(1)), is combined with the message string to produce a message catalog source line. The message source line is assigned to the set whose number is the current value of as set by the last directive encountered. If has not yet been defined when a message line is found, the message is output without a set number specification. If more than one message is found belonging to the same set and message number, the last message found is output; any others are silently discarded. Conditional compilation and instructions in the C source files are ignored. Options recognizes the following command-line options: Merge identically numbered sets from multiple input files so that can process the output. Define symbol sym. Cause symbol sym to be undefined. Consider all #ifdefs to extract messages from the input file. Options and will be used to select print specifiers if this option is not used. Outputs all error messages issued by By default, does not display the error messages issued by The command extracts messages from a message catalog file created by Messages are written to standard output in a format suitable for edit- ing and re-input to EXTERNAL INFLUENCES
Environment Variables determines the interpretation of messages as single-byte and/or multi-byte characters. determines the language in which messages are displayed. If or is not specified in the environment or is set to the empty string, the value of is used as a default for each unspecified or empty variable. If is not specified or is set to the empty string, a default of (see lang(5)) is used instead of If any internationalization variable contains an invalid setting, and behave as if all internationalization variables are set to See environ(5). International Code Set Support Single-byte and multi-byte character code sets are supported. WARNINGS
The and commands are HP proprietary, not portable to other vendors' systems, and will not be provided in future HP-UX releases. AUTHOR
and were developed by HP. SEE ALSO
findstr(1), gencat(1), insertmsg(1), catgets(3C). findmsg(1)
All times are GMT -4. The time now is 12:48 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy