Sponsored Content
Top Forums Shell Programming and Scripting Files exists with same name and not empty Post 303003484 by jim mcnamara on Thursday 14th of September 2017 10:08:53 AM
Old 09-14-2017
Just using simple commands:
Code:
export ok=0   # means files are there and non-empty

test_sz() {  # function to return 0 or 1
{
    sz="$1"
    sz=$( wc -c "$sz)
    sz=${sz:0:1}  # first character of sz string
    retval=0   # assume failure
    [ $sz -gt 0 ]  && retval=1
    return retval
}
[[ -e 1.txt && -e 2.txt && 3.txt ]] &&  ok=1 || echo 'files missing'
if [ ok -eq 1 ]; then 
   [[ $(test_sz 1.txt) -eq 0 || $(test_sz 2.txt) -eq 0  || $(test_sz 3.txt) -eq 0  ]] && ok=0
fi
if  [ ok -eq 0 ] ; then
   echo 'file(s) did not pass requirements'
   exit 1
fi
# rest of script here

This can be shortened, but it is meant to be a clear example.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

File exists and is empty

I've got a script with this snippet: if then I know that the -s indicates that the file exists and is not empty. How can I specify that the file exists, but is empty? I thought I could do: if ] then But this generates a "else unmatched" error on the else that follows. (5 Replies)
Discussion started by: dstinsman
5 Replies

2. Shell Programming and Scripting

HOW TO CHECK ONLY .C FILES EXISTS OR NOT IN A FOLDER using IF in C shell script?

Hi friends.. I hav a problem.... I dont know how to check .c files exists r not in a folder using IF in C shell script actually i tried like this if(=~ *.c) even though some .c files or there in the current folder..it is not entering int o the if control statement...... (17 Replies)
Discussion started by: p.hemadrireddy
17 Replies

3. Shell Programming and Scripting

Copy Files to Dir and Check If File Exists

Hi everyone. I am trying to write a bash script that will copy files from one directory to another but I need to be able to check the directory that I'm copying the files to and see if the file already exists. If it does I need to add a number at the end of the copied file. Thanks for your help. (3 Replies)
Discussion started by: snag49ers
3 Replies

4. Shell Programming and Scripting

How to see the list of files which exists with nonzero bytes

Hi, I would like to see the file list which contains the data. Ex : - When I enter the "ls -ltr" command it will show all the files which are exists in the directory, But I want only those files list which are non zero byte by using only ls command. I knew that I can write a script with... (12 Replies)
Discussion started by: kandi.reddy
12 Replies

5. Shell Programming and Scripting

Find records between two files which are not exists in one another in one

Hello all, Would like to know how to find records between two files which are not exists in one another in one. For example: I've two files "fileA" and "fileB" and want to find record from "fileB" which does not exists in "fileA". fileA -------- ABCD DEFG GHIJ KLMN NOPQ RSTU VUWX... (5 Replies)
Discussion started by: nvkuriseti
5 Replies

6. Shell Programming and Scripting

check if files exists

i writing a program that checks if any .txt files exist in the current directory if it does, then it lists the files... i have got everything right, except the validation part doesnt work! .... if then ls *.txt else echo "file not found" everytime it tells me file not found!! by... (3 Replies)
Discussion started by: bshell_1214
3 Replies

7. UNIX for Dummies Questions & Answers

check if two files exists at the same time in one location

Hi friends, I am trying to check if the two files i am expecting are created in a specific location. if both files does not exist, do an echo if -a ]; then echo "files not found" fi It gives me the following message: bash: Please help! :) (3 Replies)
Discussion started by: kokoro
3 Replies

8. UNIX for Dummies Questions & Answers

Outputting 1 file per row if pattern exists between files

I have many files that can have various amounts of rows. I essentially want to output each row into a new file if a pattern is matched between two files. I have some code that does something similar but I want it to output every single input row from every file into a separate output file; that... (5 Replies)
Discussion started by: verse123
5 Replies

9. Shell Programming and Scripting

How to check more than 1 file specified files exists?

Hi all, One of my script crated created 2 files in a dirs Output.log and Output.tmp. Now in another script i need to check if both of the above mentioned files are present in a directory or not. I know to check one file but need to check both the files. Anyone could please tell me how... (3 Replies)
Discussion started by: girijajoshi
3 Replies

10. UNIX for Beginners Questions & Answers

Code for checking if certain no of files exists

Hi, I am writing the shell script in ksh to check certain no of files exists,In my case there are 7 files exist like below Sales1_timstamp.csv Sales2_timstamp.csv Sales3_timstamp.csv Sales4_timstamp.csv Sales5_timstamp.csv Sales7_timstamp.csv Sales7_timstamp.csv Once all the files... (4 Replies)
Discussion started by: SRPR
4 Replies
unix2dos(1)						      General Commands Manual						       unix2dos(1)

NAME
unix2dos - UNIX to DOS text file format converter SYNOPSYS
unix2dos [options] [-c convmode] [-o file ...] [-n infile outfile ...] Options: [-hkqV] [--help] [--keepdate] [--quiet] [--version] DESCRIPTION
This manual page documents unix2dos, the program that converts text files in UNIX format to DOS format. OPTIONS
The following options are available: -h --help Print online help. -k --keepdate Keep the date stamp of output file same as input file. -q --quiet Quiet mode. Suppress all warning and messages. -V --version Prints version information. -c --convmode convmode Sets conversion mode. Simulates unix2dos under SunOS. -o --oldfile file ... Old file mode. Convert the file and write output to it. The program default to run in this mode. Wildcard names may be used. -n --newfile infile outfile ... New file mode. Convert the infile and write output to outfile. File names must be given in pairs and wildcard names should NOT be used or you WILL lost your files. EXAMPLES
Get input from stdin and write output to stdout. unix2dos Convert and replace a.txt. Convert and replace b.txt. unix2dos a.txt b.txt unix2dos -o a.txt b.txt Convert and replace a.txt in ASCII conversion mode. Convert and replace b.txt in ISO conversion mode. unix2dos a.txt -c iso b.txt unix2dos -c ascii a.txt -c iso b.txt Convert and replace a.txt while keeping original date stamp. unix2dos -k a.txt unix2dos -k -o a.txt Convert a.txt and write to e.txt. unix2dos -n a.txt e.txt Convert a.txt and write to e.txt, keep date stamp of e.txt same as a.txt. unix2dos -k -n a.txt e.txt Convert and replace a.txt. Convert b.txt and write to e.txt. unix2dos a.txt -n b.txt e.txt unix2dos -o a.txt -n b.txt e.txt Convert c.txt and write to e.txt. Convert and replace a.txt. Convert and replace b.txt. Convert d.txt and write to f.txt. unix2dos -n c.txt e.txt -o a.txt b.txt -n d.txt f.txt DIAGNOSTICS
BUGS
The program does not work properly under MSDOS in stdio processing mode. If you know why is that so, please tell me. AUTHOR
Benjamin Lin - ( blin@socs.uts.edu.au ) MISCELLANY
Tested environment: Linux 1.2.0 with GNU C 2.5.8 SunOS 4.1.3 with GNU C 2.6.3 MS-DOS 6.20 with Borland C++ 4.02 Suggestions and bug reports are welcome. SEE ALSO
dos2unix(1) 1995.03.31 unix2dos v2.2 unix2dos(1)
All times are GMT -4. The time now is 12:24 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy