![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | 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 and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| check if remote file exists | hcclnoodles | Shell Programming and Scripting | 2 | 08-27-2008 06:53 PM |
| Check File Exists and compare to previous day file script | rbknisely | Shell Programming and Scripting | 3 | 02-07-2008 11:53 AM |
| check if file exists on remote system ? | hcclnoodles | Shell Programming and Scripting | 2 | 10-26-2006 05:08 AM |
| check if exists a .ZIP file and unzip it using ftp | DebianJ | Shell Programming and Scripting | 1 | 05-05-2005 05:46 PM |
| perl ftp check file exists | methos | Shell Programming and Scripting | 2 | 06-18-2003 09:21 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Hi guys,
How would i check a file exists with certainprefix? i have a directory with some files: ABC1 ABC2 ABC3 etc.. and want to do: please note i am using the korn shell environment.As when i gone through some stuff on then net i came to know some of the options will work differently based on the working shell environment.tht's wy i am specially mentioning my envrionment. Code: if [file exists with prefix ABC*] then do something else do something else fi Any one could help me on this!!!!! Advanced Thanks Narasimharao. |
|
||||
|
Hi redoubtable,
the below code is working for only exact file names(i mean the -f option).could you please tell me the way for finding files with certain prefix.I know the find command.but i need another way by using simple if command and along with their options. Hi can any one please help me on this.......... Advanced Thanks Narasimharao. |
|
||||
|
The code I gave you works for filenames starting with "ABC". ABC1, ABC2, ABC3. Code:
redoubtable@Tsunami ~ $ ls -l ABC* -rw-r--r-- 1 root root 0 2008-08-19 11:42 ABC1 -rw-r--r-- 1 root root 0 2008-08-19 11:42 ABC2 -rw-r--r-- 1 root root 0 2008-08-19 11:42 ABC3 redoubtable@Tsunami ~ $ Code:
redoubtable@Tsunami ~ $ ./s.ksh file exists. redoubtable@Tsunami ~ $ cat s.ksh #!/bin/ksh if [ -f ABC* ] then echo file exists. else echo not fi redoubtable@Tsunami ~ $ The '*' provides the capability of matching not only exact file names but also every file name starting with ABC. Remember that you must not use " in ABC. Example: This is ok: Code:
if [ -f ABC* ] This is wrong: Code:
if [ -f "ABC*" ] |
|
||||
|
You can do something like this: Code:
for file in *; do
prefix=echo ${file:0:3}
if [ "$prefix" = "ABC" ]; then
# do something
else
# do something else
fi
done
Regards Last edited by Franklin52; 08-19-2008 at 10:18 AM.. Reason: ${file:1:3} must be ${file:0:3} |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|