This is a discussion on Checking files exist within the Shell scripting forums, part of the Development/Scripting category; Hi there. New to the forum so hello. I am currently studying a Computer Science degree and have some linux ...
|
|||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| Sponsored Links | ||
|
|
|
||||
|
Welcome to forum!
Use the -f option Code:
[ -f /etc/fack.file ] && echo "File exists" || echo "Sorry " Code:
if [ -f /path/to/a.txt ]; then # file exist do something echo "File found" else # file does NOT exist do something like give error echo "Error file not found" fi
__________________
Rocky Jr. You may have my body & soul, but you will never touch my pride! If you have knowledge, let others light their candles at it. Certified to work on HP-UX / Sun Solaris / RedHat |
|
||||
|
Sorry I should have been more specific. The code I was looking for was how to get the temp files to increment by 1 until the file is not found.
I thought it would have been a for, while or until loop e.g. for (( i=0; i<=100; i++ )) do if ! [ -s file$i.txt ] then # use this as file name else # increment the file name by 1 and try again until a file does not exist done basically what I'm trying to represent is that we check to see that file0.txt exists. If it does we then check to see if file1.txt exists and so on until it finds that filen.txt in which case it some code under: if ! [ -s file$1.txt ] then # use this as file name and execute next code sort -r file$i.txt but it needs to do this for multiple temporary files. Thanks for your help. Last edited by seeker082; 02-19-2008 at 09:55 PM. Reason: Mistake in code I wrote |
|
|||
|
Can't you use mktemp(1) ? You can avoid the loop then.
[1] mktemp(1): make temporary filename - Linux man page |
|
||||
|
Hi could you be a bit more specific?
I have tried to use the mktemp command with no joy. The code I have for doing the job is: sort $1 > tempfile1.txt sort $2 > tempfile2.txt sort $3 > tempfile3.txt tail -n 1 tempfile1.txt > tempfile4.txt tail -n 1 tempfile2.txt > tempfile5.txt tail -n 1 tempfile3.txt > tempfile6.txt sort -m tempfile4.txt tempfile5.txt tempfile6.txt > tempfile7.txt sort -r tempfile7.txt > output.txt Thanks. |
|
|||
|
Quote:
Code:
for f in $1 $2 $3 do sort $f | tail -n 1 done | sort -r > output.txt |
![]() |
| Bookmarks |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) |
|
| Thread Tools | |
| Display Modes | |
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| checking windows file from linux | jhn_daz@yahoo.com | Getting started tutorials | 1 | 10-31-2007 07:40 PM |
| Shell script for automatic conversion of files in tar files | kasimani | Shell scripting | 2 | 02-08-2007 03:45 PM |