Sponsored Content
Top Forums Shell Programming and Scripting How to check if a file exists in a directory? Post 302588169 by vel4ever on Saturday 7th of January 2012 07:48:07 AM
Old 01-07-2012
How to check if a file exists in a directory?

I want to perform SQL *Loader operation only if a file named "load.txt" exists in a directory "/home/loc/etc". Please help how to check this with a if condition.

Last edited by vel4ever; 01-07-2012 at 09:03 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

check if directory exists

Hi, I need to prompt for a response from a user to enter a path read dest_dir?"Please Enter Directory :" How do I do this until a valid directory is entered by the user. I can use to check the existence of the directory. However when I try the following I cannot get it to work. while ... (2 Replies)
Discussion started by: jerardfjay
2 Replies

2. Shell Programming and Scripting

how to check if masked directory exists?

I'm trying to write a script that identifies whether a directory of the form AWL.????????.IP exists. I have one that exists which is AWL.05301032.IP. When I test like this: If ] I get true, but when I test like this: If ] Or like this If ] Or any other variation of wild cards, I... (4 Replies)
Discussion started by: philplasma
4 Replies

3. UNIX for Dummies Questions & Answers

How can I check if directory exists in a makefile

Hi. I what to write a make file that inside a target I want to check if a directory exists. some like: ### make a: if ;then <command 1> else <command 2> fi ### make end Thanks a lot ---------------------- (2 Replies)
Discussion started by: zivsegal
2 Replies

4. Shell Programming and Scripting

my scripts does not check if directory exists

Hello: Can someone please help me figure out what is wrong here, my script does not move on to the "else" part even though there is no .ssh directory on my remote server: $more putkey.sh #!/bin/ksh for server in `cat list` do if ; then cat $HOME/.ssh/id_rsa.pub |ssh $server ' cat >>... (4 Replies)
Discussion started by: Sara-sh
4 Replies

5. Shell Programming and Scripting

check if a directory exists if not make it

Hey guys im trying to check if the directory exists i get a syntax error on the elif statement iv tried using else and still same result im not sure. If the directory does not exist can i just insert mkdir /tmp/old under the elif once that part gets working if ; then #do nothing elif echo... (20 Replies)
Discussion started by: musicmancanora
20 Replies

6. Shell Programming and Scripting

check if directory and file exists

cp $PATHLOGS/$DATE/*.* $TMP/logs_tmp/ cp $PATHLOGS/$DATE1/*.* $TMP/logs_tmp/ Before copying the files I have to check if the directory $DATE1 and $DATE2 exists. If directory exists then, check if the folder contains some files. if the file exists then, check if the file size is greater... (3 Replies)
Discussion started by: sandy1028
3 Replies

7. Shell Programming and Scripting

how to check if a directory exists or not.if not need to create it

Hi, I am using solaris 10 OS and bash shell.just checking for small code snippet which follows below. /export/home/vomappservers/spa/common/5.0 /export/home/vomappservers/spa/common/scripts /export/home/vomappservers/spa/tools /export/home/vomappservers/spa/scm5.0/SCCS... (5 Replies)
Discussion started by: muraliinfy04
5 Replies

8. 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

9. Shell Programming and Scripting

Check whether file exists in directory

Hi guys, I am beginner trying to learn unix. So any help is welcomed. My requirement is to check whether is a file exists in a particular directory or not. The directory path and filename are taken dynamically with user interaction. So the program should continue only if the $filename... (1 Reply)
Discussion started by: maris_markur
1 Replies

10. UNIX for Beginners Questions & Answers

Check that at least one file exists in the directory.

There are some files with suffix dates like abc_20032019.dat abc_17032019.dat If at least one file exists then perform some operation else exit from execution. Korn shell ---------------------------------- array=($inputdir/abc*.dat) If ] ] then echo " file exits" else echo " file does... (10 Replies)
Discussion started by: Rajesh123
10 Replies
Data::Phrasebook(3pm)					User Contributed Perl Documentation				     Data::Phrasebook(3pm)

NAME
Data::Phrasebook - Abstract your queries! ABSTRACT
A collection of modules for accessing phrasebooks from various data sources. SYNOPSIS
use Data::Phrasebook; my $q = Data::Phrasebook->new( class => 'Plain', loader => 'Text', file => 'phrases.txt', ); # simple keyword to phrase mapping my $phrase = $q->fetch($keyword); # keyword to phrase mapping with parameters $q->delimiters( qr{ [% s* (w+) s* %] }x ); my $phrase = $q->fetch($keyword,{this => 'that'}); DESCRIPTION
Data::Phrasebook is a collection of modules for accessing phrasebooks from various data sources. PHRASEBOOKS
To explain what phrasebooks are it is worth reading Rani Pinchuk's (author of Class::Phrasebook) article on Perl.com: <http://www.perl.com/pub/a/2002/10/22/phrasebook.html> Common uses of phrasebooks are in handling error codes, accessing databases via SQL queries and written language phrases. Examples are the mime.types file and the hosts file, both of which use a simple phrasebook design. Unfortunately Class::Phrasebook is a complete work and not a true class based framework. If you can't install XML libraries, you cannot use it. This distribution is a collaboration between Iain Truskett and myself to create an extendable and class based framework for implementing phrasebooks. CLASSES
In creating a phrasebook object, a class type is required. This class defines the nature of the phrasebook or the behaviours associated with it. Currently there are two classes, Plain and SQL. The Plain class is the default class, and allows retrieval of phrases via the fetch() method. The fetch() simply returns the phrase that maps to the given keyword. The SQL class allows specific database handling. Phrases are retrieved via the query() method. The query() method internally retrieves the SQL phrase, then returns the statement handler object, which the user can then perform a prepare/execute/fetch/finish sequence on. For more details see Data::Phrasebook::SQL. CONSTRUCTOR
new The arguments to new depend upon the exact class you're creating. The default class is "Plain" and only requires the Loader arguments. The "SQL" class requires a database handle as well as the Loader arguments. The "class" argument defines the object class of the phrasebook and the behaviours that can be associated with it. Using "Foobar" as a fake class, the class module is searched for in the following order: 1. If you've subclassed "Data::Phrasebook", for example as "Dictionary", then "Dictionary::Foobar" is tried. 2. If that failed, "Data::Phrasebook::Foobar" is tried. 3. If that failed, "Foobar" is tried. 4. If all the above failed, we croak. This should allow you some flexibility in what sort of classes you use while not having you type too much. For other parameters, see the specific class you wish to instantiate. The class argument is removed from the arguments list and the "new" method of the specified class is called with the remaining arguments. DELIMITERS
Delimiters allow for variable substitution in the phrase. The default style is ':variable', which would be passed as: $q->delimiters( qr{ :(w+) }x ); As an alternative, a Template Toolkit style would be passed as: $q->delimiters( qr{ [% s* (w+) s* %] }x ); DICTIONARIES
Simple Dictionaries Data::Phrasebook supports the use of dictionaries. See the specific Loader module to see how to implement the dictionary within your phrasebook. Using Data::Phrasebook::Loader::Ini as an example, the dictionary might be laid out as: [Stuff] language=Perl platform=Linux [Nonsense] platform=Windows The phrasebook object is then created and used as: my $q = Data::Phrasebook->new( class => 'Plain', loader => 'Ini', file => 'phrases.ini', dict => 'Nonsense', ); my $language = $q->fetch('language'); # retrieves 'Perl' my $platform = $q->fetch('platform'); # retrieves 'Windows' The former is from the default (first) dictionary, and the second is from the named dictionary ('Nonsense'). If a phrase is not found in the named dictionary an attempt is made to find it in the default dictionary. Otherwise undef will be returned. Once a dictionary or file is specified, changing either requires reloading. As this is done at the loader stage, we need to let it know what it needs to reload. This can be done with the either (or both) of the following: $q->file('phrases2.ini'); $q->dict('Stuff'); A subsequent fetch() will then reload the file and dictionary, before retrieving the phrase required. However, a reload only takes place if both the file and the dictionary passed are not the ones currently loaded. Multiple Dictionaries As of version 0.25, the ability to provide prescendence over multiple dictionaries for the same phrasebook. Using Data::Phrasebook::Loader::Ini again as an example, the phrasebook might be laid out as: [AndTheOther] language=Perl platform=Linux network=LAN [That] platform=Solaris network=WLAN [This] platform=Windows The phrasebook object is then created and used as: my $q = Data::Phrasebook->new( class => 'Plain', loader => 'Ini', file => 'phrases.ini', dict => ['This','That','AndTheOther'], ); my $language = $q->fetch('language'); # retrieves 'Perl' my $platform = $q->fetch('platform'); # retrieves 'Windows' my $network = $q->fetch('nework'); # retrieves 'WLAN' The first dictionary, if not specified and supported by the Loader module, is still used as the default dictionary. The dictionaries can be specified, or reordered, using the object method: $q->dict('That','AndTheOther','This'); A subsequent reload will occur with the next fetch call. DEDICATION
Much of the original class framework work is from Iain's original code. My code was a lot simpler and was tied to using just an INI data source. Merging all the ideas and code together we came up with this distribution. Unfortunately Iain died in December 2003, so he never got to see or play with the final working version. I can only thank him for his thoughts and ideas in getting this distribution into a state worthy of release. Iain Campbell Truskett (16.07.1979 - 29.12.2003) SEE ALSO
Data::Phrasebook::Plain, Data::Phrasebook::SQL, Data::Phrasebook::SQL::Query, Data::Phrasebook::Debug, Data::Phrasebook::Generic, Data::Phrasebook::Loader, Data::Phrasebook::Loader::Text, Data::Phrasebook::Loader::Base. SUPPORT
Please see the README file. DSLIP
b - Beta testing d - Developer p - Perl-only O - Object oriented p - Standard-Perl: user may choose between GPL and Artistic AUTHOR
Original author: Iain Campbell Truskett (16.07.1979 - 29.12.2003) Maintainer: Barbie <barbie@cpan.org> since January 2004. for Miss Barbell Productions <http://www.missbarbell.co.uk>. COPYRIGHT AND LICENSE
Copyright (C) 2003 Iain Truskett. Copyright (C) 2004-2010 Barbie for Miss Barbell Productions. This module is free software; you can redistribute it and/or modify it under the Artistic Licence v2. perl v5.10.1 2010-10-15 Data::Phrasebook(3pm)
All times are GMT -4. The time now is 02:55 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy