![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Need to write a script in UNIX to find a file if another file exists | mmdawg | Shell Programming and Scripting | 1 | 05-04-2008 07:40 PM |
| unix script to check whether particular file exists and to find its size | Balachandar | Shell Programming and Scripting | 9 | 02-05-2008 12:56 AM |
| Find lines greater than 80 characters in a file | mrgubbala | Shell Programming and Scripting | 8 | 03-10-2007 09:51 PM |
| Can I find wether a particular file exist and size greater than zero...help please | guhas | Shell Programming and Scripting | 4 | 11-28-2005 10:56 AM |
| File size greater than 0 | skammer1234 | Shell Programming and Scripting | 1 | 08-03-2002 07:30 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
My problem is that I have to make sure there are no new files being written when I start combining the files other-wise I will get a partial file only. So I am doing a count out to a file and sleeping for a few seconds and doing it again to a different file. I then do a diff on the two files. What I am having trouble with I checking to see if the output file of my diff exists and has a size greater than zero. What I want to do is loop back around and do the counts all over again if there are differences, it not, continue with the rest of the program of combing and moving. Thanks.
#!/usr/bin/perl LOOP system("wc IM0106* >count.dat"); system("sleep 5"); system("wc IM0106* >count.dat2"); system("diff count.dat count.dat2 > diff.dat"); if ( (-e diff.dat) && (-z diff.dat) ){ print "File exist and size is 0\n"; system("touch nosize.dat"); exit;} print "File exist and size is greater than 0\n"; system("sleep 15"); LOOP bach through END LOOP |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
This seems like it could be homework, but since you posted your own work instead of asking for us to write your script, I will offer this help.
You need to use awk or cut to parse out the filename from the diff output. Try this: 1) take whatever field/column is the filename from your diff output. 2) perform the byte size test on the file. diff file1 file2 |awk -F: '{ print $1 }' > diff.out if (-z diff.out) etc... Only use the -F option if you have some delimeter in your output file diff.dat. I only put this in to show you the format. The print $1 is to print the first column of the diff.dat output. Hope this helps. Again if this is not homework please forgive the assumption.
__________________
My brain is your brain |
|
#3
|
||||
|
||||
|
I would use a shell script for this. No point in using perl when all you are really doing is making system calls. You can also eliminate the temporary files (unless you need them for some later step)
Code:
#!/bin/bash
while (true)
do
COUNT=`wc IM0106*`
sleep 5
COUNT2=`wc IM0106*`
if [ $COUNT1 == $COUNT2 ]
then
echo "no difference"
touch nosize.dat
sleep 15
else
break
fi
done
# ... rest of script ...
Note: kelam_magnus posted his reply while I was composing mine. This doesn't sound like a homework problem to me, so I'll leave my script here. |
|
#4
|
|||
|
|||
|
No this is not a homework problem, something I am doing for work and trying to interface the new EDI system I put in with our legacy system, but I understand your hesitations and appreciate your feedback.
Thanks for the suggestions |
|||
| Google The UNIX and Linux Forums |